简体   繁体   English

lua5.2在windows中调用c dll

[英]lua5.2 call c dll in windows

My C code is below: 我的C代码如下:

skypeAnalyzer.h skypeAnalyzer.h

#include "lua.h" 
#include "lualib.h" 
#include "lauxlib.h"
#include "stdio.h"
#include "stdlib.h"

//dll export func
int _declspec(dllexport) luaopen_skypeAnalyzer(lua_State* L);

skypeAnalyzer.c skypeAnalyzer.c

#include "skypeAnalyzer.h"
#include <windows.h> 
#include <wincrypt.h> 

int run(lua_State* L){
    printf("------->>> Hi! %s \n", lua_tostring(L, 1));
    return 0;
}


struct luaL_Reg IrLibs[] = {

    { "run", run },
    { NULL, NULL }
};


int luaopen_skypeAnalyzer(lua_State* L)
{
    luaL_newlib(L, IrLibs);
    return 1;
}

And lua code is below: 而lua代码如下:

require "skypeAnalyzer"
skypeAnalyzer.run("Lua")

I compile dll in vs express 2013 and generate skypeAnalyzer.dll, but when I run lua code, there are the following error: 我在vs express 2013中编译dll并生成skypeAnalyzer.dll,但是当我运行lua代码时,会出现以下错误:

C:\Lua>lua52.exe skypeAnalyzer.lua
lua52.exe: C stack overflow
stack traceback:
        [C]: in ?
        [C]: in function 'require'
        C:\Lua\skypeAnalyzer.lua:1: in main chunk
        [C]: in function 'require'

How to dynamically call lua52.dll when compile the dll? 如何在编译dll时动态调用lua52.dll? How to set in VS 2013? 如何在VS 2013中设置? I compile dll in vs express 2013 and generate skypeAnalyzer.dll, but when I run lua code, there are the following error: 我在vs express 2013中编译dll并生成skypeAnalyzer.dll,但是当我运行lua代码时,会出现以下错误:

Anyone can help me? 有人可以帮帮我吗?

Your lua code is requiring itself. 你的lua代码需要自己。

Use a different name for the .dll and .lua files. .dll.lua文件使用不同的名称。

With lua 5.1 you would have gotten the slightly more useful error trace: 使用lua 5.1,您可以获得稍微有用的错误跟踪:

lua5.1: ./foo.lua:1: loop or previous error loading module 'foo'
stack traceback:
        [C]: in function 'require'
        ./foo.lua:1: in main chunk
        [C]: ?
        [C]: ?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM