Refactor and fix up a lot of code
Don't tell the boss I forgot a couple of free()s...
This commit is contained in:
parent
fe38efac42
commit
290289cbf5
12 changed files with 175 additions and 335 deletions
16
callisto.c
16
callisto.c
|
@ -8,11 +8,9 @@
|
|||
|
||||
#include "callisto.h"
|
||||
|
||||
|
||||
static const luaL_Reg loadedlibs[] = {
|
||||
{CALLISTO_CLLIBNAME, luaopen_cl},
|
||||
{CALLISTO_ENVLIBNAME, luaopen_environ},
|
||||
{CALLISTO_EXTLIBNAME, luaopen_extra},
|
||||
{CALLISTO_FSYSLIBNAME, luaopen_fs},
|
||||
{CALLISTO_JSONLIBNAME, luaopen_json},
|
||||
{CALLISTO_MATHLIBNAME, luaopen_math},
|
||||
|
@ -37,12 +35,24 @@ callisto_openall(lua_State *L)
|
|||
{
|
||||
const luaL_Reg *lib;
|
||||
|
||||
/* for every Callisto library */
|
||||
/* for each Callisto library except extra */
|
||||
for (lib = loadedlibs; lib->func; lib++) {
|
||||
lua_newtable(L); /* make a new table for the library */
|
||||
lib->func(L); /* load library */
|
||||
lua_setglobal(L, lib->name);
|
||||
}
|
||||
/* inject extra into the global environment */
|
||||
luaopen_extra(L);
|
||||
lua_pushnil(L);
|
||||
while (lua_next(L, -2) != 0) { /* for each key in the extra library */
|
||||
/* if the key is not a string, move on to the next one */
|
||||
if (!lua_isstring(L, -2)) {
|
||||
lua_pop(L, 1);
|
||||
continue;
|
||||
}
|
||||
/* assign the value to a global */
|
||||
lua_setglobal(L, lua_tostring(L, -2));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue