Last active
January 2, 2016 11:49
-
-
Save hanxi/8299600 to your computer and use it in GitHub Desktop.
This file contains 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" | |
#include <stdio.h> | |
int | |
dylib_add(lua_State* L) { | |
int a = lua_tonumber(L,1); | |
int b = lua_tonumber(L,2); | |
int c = a+b; | |
lua_pop(L,2); | |
lua_pushnumber(L,c); | |
return 1; | |
} | |
int dylib2_test(lua_State* L); | |
int start(lua_State* L) { | |
luaL_requiref(L, "dylib2.test", dylib2_test, 0); | |
return 0; | |
} | |
int | |
luaopen_dylib_test(lua_State* L) { | |
luaL_Reg l[] = { | |
{ "add", dylib_add }, | |
{ "start", start }, | |
{ NULL, NULL }, | |
}; | |
luaL_checkversion(L); | |
luaL_newlib(L,l); | |
return 1; | |
} | |
int | |
dylib2_test(lua_State* L) { | |
luaL_Reg l[] = { | |
{ "add", dylib_add }, | |
{ NULL, NULL }, | |
}; | |
luaL_checkversion(L); | |
luaL_newlib(L,l); | |
return 1; | |
} | |
This file contains 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
dylib = require "dylib.test" | |
local c = dylib.add(1,2) | |
print(c) | |
dylib.start() | |
dylib = require "dylib2.test" | |
local c = dylib.add(1,2) | |
print(c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment