Lua5.2 call c dll on windows

My C code is below:

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

#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 the lua code is below:

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

      

I compile the dll in vs express 2013 and create skypeAnalyzer.dll but when I run the lua code the following error occurs:

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 compiling dll? How to install in VS 2013? I am compiling the dll in vs express 2013 and generating the skypeAnalyzer.dll file, but when I run the lua code the following error occurs:

Can anyone help me?

+3


source to share


1 answer


Your lua code requires itself.

Use a different name for the files .dll

and .lua

.



With lua 5.1, you would get a slightly more useful error tracing:

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]: ?

      

+2


source







All Articles