// // Loader Interface // int create(void) { if (!states) { states = kh_init(m32); } lua_State* l = luaL_newstate(); openlualibs(l); regluafuncs(l); struct instance *inst = instance_init(l); // Find an unused key int ret = 0; int id = -1; khint_t key; do { id = _nextid++; key = kh_put(m32, states, id, &ret); } while (0 == ret); if (ret > 0) { kh_value(states, key) = inst; return id; } else { return 0; } }
static bool initialize_lua(language_t*li, size_t mem_size) { if(li->internal) return true; // already initialized li->internal = calloc(1, sizeof(lua_internal_t)); lua_internal_t*lua = (lua_internal_t*)li->internal; lua->li = li; lua_State*l = lua->state = lua_open(); openlualibs(l); return true; }
lua_State* inittorch(AAssetManager* manager) { /* Declare a Lua State, open the Lua State */ lua_State *L; L = lua_open(); // set the asset manager android_fopen_set_asset_manager(manager); THApkFile_setAAssetManager((void *) manager); openlualibs(L); luaopen_landroidprint(L); // add an android module loader to package.loaders lua_getglobal(L, "package"); lua_getfield(L, -1, "loaders"); int numloaders = lua_objlen(L, -1); lua_pushcfunction(L, loader_android); lua_rawseti(L, -2, numloaders+1); lua_pop(L, 1); return L; }
apr_status_t lua_lkl_main(const char * script_file, apr_pool_t * root_pool) { gp = root_pool; /* initialize Lua */ L = lua_open(); if(NULL == L) return -1; /* load Lua base libraries & our extensions */ openlualibs(L); /* run the script */ lua_run_script(L, script_file); /* cleanup Lua */ lua_close(L); return APR_SUCCESS; }
void sat_init(lua_State* L) { sat_partinfos = calloc(1, sizeof(Node)); satellites = calloc(1, sizeof(Node)); // load the library openlualibs(L); // run the load script const char* startup = "src/scripts/load.lua"; int s = luaL_loadfile(L, startup); if ( s==0 ) { s = lua_pcall(L, 0, LUA_MULTRET, 0); if(s) { fprintf(stderr, "Lua error: %s\n", lua_tostring(L, -1)); exit(0); } printf("initialized\n"); } else { fprintf(stderr, "Lua load error: %s\n", lua_tostring(L, -1)); exit(0); } }