diff options
author | Determinant <[email protected]> | 2015-06-22 19:01:29 +0800 |
---|---|---|
committer | Determinant <[email protected]> | 2015-06-22 19:01:29 +0800 |
commit | 2497fd9e7a0fae5ee4887890d7a312e0e08a93b8 (patch) | |
tree | 382f97575bd2df9ee6abb1662b11b279fc22d72b /nerv/nerv.c | |
parent | 196e9b48a3541caccdffc5743001cced70667091 (diff) |
major change: use luarocks to manage project
Diffstat (limited to 'nerv/nerv.c')
-rw-r--r-- | nerv/nerv.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/nerv/nerv.c b/nerv/nerv.c new file mode 100644 index 0000000..a59eadc --- /dev/null +++ b/nerv/nerv.c @@ -0,0 +1,38 @@ +#include "common.h" + +extern void nerv_example_init(lua_State *L); +extern void nerv_matrix_init(lua_State *L); +extern void nerv_io_init(lua_State *L); + +static const luaL_Reg nerv_utils_methods[] = { + {"setmetatable", luaT_lua_setmetatable}, + {"getmetatable", luaT_lua_getmetatable}, + {"newmetatable", luaT_lua_newmetatable}, + {"typename", luaT_lua_typename}, + {NULL, NULL} +}; + +void nerv_utils_init(lua_State *L) { + luaL_register(L, NULL, nerv_utils_methods); +} + +int luaopen_libnerv(lua_State *L) { + lua_newtable(L); + /* duplicate table */ + lua_pushvalue(L, -1); + /* set table to global index */ + lua_setfield(L, LUA_GLOBALSINDEX, "nerv"); + /* A table reference still remains. + * + * The following initialization functions should obey to the rule that they + * maintain the stack properly to guarantee the stack stays the same before + * and after invoking the call (i.e. stay balanced). + * + * Also note that they can make use of the value at top of the stack which + * references to the `nerv` global table. */ + nerv_utils_init(L); + nerv_example_init(L); + nerv_matrix_init(L); + nerv_io_init(L); + return 1; +} |