Last active
January 4, 2016 05:39
-
-
Save annidy/8576440 to your computer and use it in GitHub Desktop.
lua扩展模块示例
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: | |
gcc -shared -o testc.so testc.c -llua | |
win: | |
cl /MD /O2 -c -Ftestc.obj -I"%LUA_DEV%\include" testc.c /D __WINNT__ | |
link -dll -def:testc.def -out:testc.dll "%LUA_DEV%\lib\lua5.1.lib" testc.obj |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t = require "testc" | |
t.test({1,2,3}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <lua.h> | |
#include <lauxlib.h> | |
static int test(lua_State *L) | |
{ | |
if (lua_istable(L, 1)) { | |
lua_pushnil(L); | |
while(lua_next(L, 1)) { | |
printf("%d", lua_tointeger(L, -1)); | |
lua_pop(L, 1); | |
} | |
} | |
return 0; | |
} | |
static const luaL_Reg testclib[] = { | |
{"test", test}, | |
{NULL, NULL}, | |
}; | |
int luaopen_testc(lua_State *L) | |
{ | |
luaL_register(L, "testc", testclib); | |
return 1; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LIBRARY testc | |
EXPORTS | |
luaopen_testc @1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment