Skip to content

Instantly share code, notes, and snippets.

@hanxi
Last active January 2, 2016 11:49
Show Gist options
  • Save hanxi/8299600 to your computer and use it in GitHub Desktop.
Save hanxi/8299600 to your computer and use it in GitHub Desktop.
#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;
}
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