static void *Run( void *data ) { intf_thread_t *p_intf = data; intf_sys_t *p_sys = p_intf->p_sys; lua_State *L = p_sys->L; if( luaL_dofile( L, p_sys->psz_filename ) ) { msg_Err( p_intf, "Error loading script %s: %s", p_sys->psz_filename, lua_tostring( L, lua_gettop( L ) ) ); lua_pop( L, 1 ); } return NULL; }
void fs_emu_theme_init_lua(void) { fs_log("fs_emu_theme_init_lua\n"); char *path = g_build_filename(g_fs_emu_theme.path, "theme.lua", NULL); if (fs_path_exists(path)) { int result = luaL_dofile(fs_emu_lua_state, path); if (result != 0) { fs_emu_warning("Error loading/running theme.lua"); fs_emu_lua_log_error("Error loading/running theme.lua"); } } free(path); }
int main() { lua_State * L = luaL_newstate(); luaL_openlibs(L); RegisterFoo(L); int erred = luaL_dofile(L, "fun.lua"); if(erred) std::cout << "Lua error: " << luaL_checkstring(L, -1) << std::endl; lua_close(L); return 0; }
void IPU::create() { _wfreopen_s( &m_hLogFile, L"stdout.txt" , L"w+t" , stdout); m_logThreadExitSign=false; _beginthread(&updateLog,0,NULL); out("create"); m_L=lua_open(); if(m_L==NULL) { out("lua_open failed"); } else { out("lua_open succeeded"); } loadModules(); if(luaL_dofile(m_L,"main.lua")!=0) { out("An error detected when loading main.lua"); out("////////////////Error detail////////////////"); out(lua_tostring(m_L,-1)); out("////////////////////////////////////////////"); } else { out("lua ok"); m_isLuaOK=true; } m_hAccelTable = LoadAccelerators( GetModuleHandle(NULL), MAKEINTRESOURCE(IDC_IPU)); createWindow(); #ifdef _x64 out("starting x86 ime hook layer"); PROCESS_INFORMATION pi; STARTUPINFO si; ZeroMemory(&si,sizeof(si)); si.cb=sizeof(si); CreateProcess(_T("zs_x86layer.exe"),NULL,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi); #endif }
struct env * env_create(const char *file) { struct env *env = (struct env *)service_alloc(0, sizeof *env); spinlock_init(&env->lock); env->L = luaL_newstate(); if (file && LUA_OK != luaL_dofile(env->L, file)) { fprintf(stderr, "env init failed, %s\n", lua_tostring(env->L, -1)); lua_close(env->L); spinlock_unit(&env->lock); service_alloc(env, 0); return 0; } return env; }
bool CGUIManager::readGui(const std::string &fileName) { if (!lua) init(); std::string scriptPath = CResourceManager::getInstance()->getGUIFolder() + fileName; bool ret = !luaL_dofile(lua, scriptPath.c_str()); if(!ret) { // TODO: Залогировать! std::string log(lua_tostring(lua, -1)); std::cout << log; } close(); return ret; }
void* luaLoop(void* data) { while(1) { lua_State* L = lua_open(); if (luaL_dofile(L, "config.lua")) { fprintf(stderr, "%s", lua_tostring(L, -1)); lua_pop(L, 1); /* pop error message from the stack */ } luaL_openlibs(L); lua_register(L, "sleep", luaSleep); lua_register(L, "openLog", luaOpenLog); lua_register(L, "log", luaLog); lua_register(L, "closeLog", luaCloseLog); lua_register(L, "getTime", luaGetTime); lua_register(L, "startSignal", luaStartSignal); lua_register(L, "clearButtonEvents", luaClearButtonEvents); lua_register(L, "getButtonEvent", luaGetButtonEvent); lua_register(L, "getButtonState", luaGetButtonState); lua_register(L, "setState", luaSetState); lua_register(L, "setAdminState", luaSetAdminState); lua_register(L, "setSignNr", luaSetSignNr); lua_register(L, "getWebAction", luaGetWebAction); if (luaL_dofile(L, "script.lua")) { fprintf(stderr, "%s", lua_tostring(L, -1)); lua_pop(L, 1); /* pop error message from the stack */ } luaCloseLog(L); lua_close(L); } return NULL; }
struct c101_Company* c101_parse(const char* file) { jmp_buf env; if (setjmp(env)) return NULL; lua_State* lua = luaL_newstate(); if (!lua) c101_error(1, "Could not create Lua state", &env); luaL_openlibs(lua); if (luaL_dofile(lua, "parsing.lua")) parseError(lua, NULL, &env); lua_pushcfunction(lua, c101_parseCompany ); lua_setglobal (lua, "c101_parseCompany" ); lua_pushcfunction(lua, c101_parseDepartment ); lua_setglobal (lua, "c101_parseDepartment"); lua_pushcfunction(lua, c101_parseEmployee ); lua_setglobal (lua, "c101_parseEmployee" ); lua_pushcfunction(lua, c101_endDepartment ); lua_setglobal (lua, "c101_endDepartment" ); lua_getglobal(lua, "parseCompany"); struct ParseData data = {0}; lua_pushlightuserdata(lua, &data); if (luaL_dofile(lua, file)) parseError(lua, &data, &env); if (lua_pcall(lua, 2, 0, 0)) parseError(lua, &data, &env); lua_close(lua); c101_freeVector(&data.stack); return data.company; }
int main(int argc, char ** argv) { int i; int use_logfile = 1; for(i = 0; i < argc; i++) if(strcmp(argv[i], "--stderr") == 0) use_logfile = 0; log_init(use_logfile); switch_to_game_directory(); // load lua and libraries lua_State *L = lua_open(); luaL_openlibs(L); init_preloaders(L); // load arguments (and pre-arguments) into a global 'arg' table lua_newtable(L); for(i = 0; i < argc; i++) { lua_pushstring(L, argv[i]); lua_rawseti(L, -2, i); } lua_setglobal(L, "arg"); // open app, with error reporting lua_getglobal(L, "debug"); lua_getfield(L, -1, "traceback"); int error = luaL_dofile(L, "init.lua"); if(!error) { // load command-line arguments as function arguments lua_checkstack(L, argc - 1); for(i = 1; i <= argc - 1; i++) lua_pushstring(L, argv[i]); error = lua_pcall(L, argc - 1, 0, -2); // run the result } if(error) log_messagef("fatal error: %s", lua_tostring(L, -1)); else log_message("exiting normally"); lua_close(L); return error; }
bool ScriptEngine::start(lua_State *L/* = nullptr*/) { if (!m_luaState) { if (L) { m_luaState = L; } else { m_luaState = luaL_newstate(); } if (!m_luaState) { return false; } luaL_openlibs(m_luaState); //extern void toluafix_open(lua_State* L); //toluafix_open(m_luaState); //extern int luaopen_toluaInterface (lua_State* tolua_S); //luaopen_toluaInterface(m_luaState); LuaHelper::init(m_luaState); extern int luaopen_ScriptInterface(lua_State *L); luaopen_ScriptInterface(m_luaState); if (!L) { int e = luaL_dofile(m_luaState, "script/main.lua"); if ( e ) { printf("%s\n", lua_tostring(m_luaState, -1)); lua_pop(m_luaState, 1); lua_close(m_luaState); m_luaState = nullptr; return false; } } return true; } else { assert(false); return true; } }
int testClass() { Test::Tst_B* b = new Test::Tst_B; // instance used in Lua code lua_State* L = lua_open(); luaL_openlibs(L); register_all_autogentestclassbindings(L); luaL_dofile(L,"script/tclass.lua"); lua_close(L); delete b; return 0; }
int _tmain(int argc, _TCHAR* argv[]) { lua_State* L = luaL_newstate(); if ( L == NULL ) return -1; luaL_openlibs(L); Bridge11<F**k>::RegisterClass(L); luaL_dofile(L, "D:\\code\\toys\\Bridge1.0\\test.lua"); lua_close(L); return 0; }
void LuaStateECS::loadScript(const std::string& path) const { lua_State* L = mpImpl->pL.get(); int status = luaL_dofile(L, path.c_str()); if (status) { throw std::runtime_error("LuaStateECS::loadScript: Could not load Lua script."); } luabridge::LuaRef mainRef(luabridge::getGlobal(L, "main")); if (mainRef.isNil() || !mainRef.isFunction()) { throw std::runtime_error("LuaStateECS::loadScript: Could not find main function."); } mpImpl->mainRef = mainRef; }
int CLuaSVM::DirectExecuteFile(const char* path) { if (mbShutScript) { return 1; } int ret= luaL_dofile(mLS, path); if (ret !=0) { printf("Error occurs when calling luaL_dofile() Hint Machine 0x%x\n",ret); printf("Error: %s", lua_tostring(CLuaSVM::GetSingleton().mLS,-1)); return 1; } return 0; }
void Player::useItem(lua_State* L, Item* i){ luaL_dofile(L, i->getScript()); for (int j = 0; j < invSize; j++){ if (i == getInv()[j]) index = j; } i->decrNum(); if (i->getNumberOf() <= 0){ for (int j = index + 1; j < invSize; j++){ inventory[j - 1] = inventory[j]; } inventory[invSize - 1] = NULL; invSize--; } }
int TDLuaMgr::executeScriptFile(const char* filename) { assert(filename != nullptr); lua_State* lusState = this->getLuaState(); int nRet = luaL_dofile(lusState, filename); if (nRet != 0) { const char* info = lua_tostring(lusState, -1); cocos2d::log("[LUA ERROR] %s", lua_tostring(lusState, -1)); lua_pop(lusState, 1); return nRet; } return 0; }
int main () { Test::Tst_B* b = new Test::Tst_B; // instance used in Lua code lua_State* L = lua_open(); luaL_openlibs(L); tolua_tclass_open(L); luaL_dofile(L,"tclass.lua"); lua_close(L); delete b; return 0; }
item nextKey(char *filename, char *table, char *key) { item next; lua_State *L = lua_open(); luaL_openlibs(L); luaL_dofile(L, filename); lua_getglobal(L, table); lua_pushstring(L, key); lua_next(L, -2); next.key = (char*)lua_tostring(L, -2); if(lua_istable(L, -1)) next.value = "istable"; else next.value = (char*)lua_tostring(L, -1); return next; }
item firstKey(char *filename, char *table) { item first; lua_State *L = lua_open(); luaL_openlibs(L); luaL_dofile(L, filename); lua_getglobal(L, table); lua_pushnil(L); lua_next(L, -2); first.key = (char*)lua_tostring(L, -2); if(lua_istable(L, -1)) first.value = "istable"; else first.value = (char*)lua_tostring(L, -1); return first; }
XMFLOAT3 LuaScript::GetVectorData( char *variable ) { XMFLOAT3 temp; luaL_dofile(L, this->GetPath() ); lua_getglobal(L, variable); if ( lua_istable(L, -1) ) { temp.x = GetField("x"); temp.y = GetField("y"); temp.z = GetField("z"); } return temp; }
int lua_dofile(lua_State *L, const char *name) { char path[100]; snprintf(path, 100, "scripts/%s", name); if (luaL_dofile(L,path)) { if (lua_isstring(L, -1)) DebugPrintf("Error while loading %s: %s\n", path, lua_tostring(L, -1)); else DebugPrintf("Unknown error while loading %s\n", path); lua_pop(L, 1); return 1; } return 0; }
void StartupConfig::init() { DLOG(INFO) << "Loading startup config."; lua_State* L = luaL_newstate(); int ret = luaL_dofile(L, "./script/startup_config.lua"); if (ret) { LOG(WARNING) << "Failed to load the startup config file. Reason: " << lua_tostring(L, -1); return; } lua_pushvalue(L, LUA_GLOBALSINDEX); lua_pushnil(L); while (lua_next(L, -2)) { if (lua_type(L, -2) != LUA_TSTRING) { lua_pop(L, 1); continue; } int type = lua_type(L, -1); switch (type) { case LUA_TSTRING: { const char* value = lua_tostring(L, -1); const char* key = lua_tostring(L, -2); stringMap[key] = value; break; } case LUA_TBOOLEAN: { bool value = lua_toboolean(L, -1); const char* key = lua_tostring(L, -2); boolMap[key] = value; break; } case LUA_TNUMBER: { double value = lua_tonumber(L, -1); const char* key = lua_tostring(L, -2); doubleMap[key] = value; break; } default: break; } lua_pop(L, 1); } lua_pop(L, 1); lua_close(L); L = 0; }
int main(int argc, char** argv) { lua_State* L =luaL_newstate(); //Create lua vm luaL_openlibs(L); //Register standard library luaL_dofile(L, "hello.lua"); lua_getglobal(L, "test"); lua_pushstring(L, "a"); lua_gettable(L, -2); //Now stack top is test[a] if (lua_isnumber(L, -1) == 0) { printf("wrong data type\n"); return 1; } int value = lua_tointeger(L, -1); printf("test[a] = %d\n", value); lua_pop(L, 1); //pop value, stack top is table test lua_pushstring(L, "add"); lua_pushinteger(L, 1111); lua_settable(L, -3); //start to iterator test lua_pushnil(L); while(lua_next(L, -2) != 0) { //get key const char* key = lua_tostring(L, -2); if (lua_isnumber(L, -1) == 1) { int iter_value = lua_tointeger(L, -1); printf("key=%s value=%d\n", key, iter_value); } else if (lua_isstring(L, -1) == 1) { const char* iter_value = lua_tostring(L, -1); printf("key=%s value=%s\n", key, iter_value); } lua_pop(L, 1); //pop value and keep key for next iterator } return 0; }
int main(int argc, const char * argv[]) { if (argc < 2) { printf("no input path\n"); exit(1); } const char* apppath = argv[0]; char* path = strrchr(argv[0], '/'); char buff[1024] = {0}; strncat(buff, apppath, path ? (path - apppath + 1) : 0); strcat(buff, "converter.lua"); lua_State* L = lua_open(); luaL_openlibs(L); luaopen_cjson(L); luaopen_spinebinary(L); luaL_dofile(L, buff); FILE* file = fopen(argv[1], "r"); if (!file) { printf("can not open file: %s\n", argv[1]); exit(1); } fseek(file, 0, SEEK_END); size_t len = ftell(file); char* data = (char*)malloc(len); fseek(file, 0, SEEK_SET); fread(data, 1, len, file); fclose(file); lua_pushcfunction(L, _traceback); lua_getglobal(L, "convert"); luaL_checktype(L, -1, LUA_TFUNCTION); lua_pushlstring(L, data, len); luaL_gsub(L, argv[1], ".json", ".skel"); lua_pcall(L, 2, 0, -4); lua_close(L); free(data); return 0; }
QuviError l_exec_scan_script_parse(gpointer p, gpointer _qss, const gchar *data) { _quvi_script_t qss; _quvi_scan_t qs; lua_State *l; qss = (_quvi_script_t) _qss; qs = (_quvi_scan_t) p; l = qs->handle.quvi->handle.lua; lua_pushnil(l); if (luaL_dofile(l, qss->fpath->str)) luaL_error(l, "%s", lua_tostring(l, -1)); lua_getglobal(l, script_func); if (!lua_isfunction(l, -1)) { luaL_error(l, "%s: the function `%s' was not found", qss->fpath->str, script_func); } lua_newtable(l); l_set_reg_userdata(l, USERDATA_QUVI_T, (gpointer) qs->handle.quvi); l_setfield_s(l, SS_INPUT_URL, qs->url.input->str, -1); l_setfield_s(l, SS_CONTENT, data, -1); if (lua_pcall(l, 1, 1, 0)) { g_string_assign(qs->handle.quvi->status.errmsg, lua_tostring(l, -1)); return (QUVI_ERROR_SCRIPT); } if (!lua_istable(l, -1)) { static const gchar *_E = "%s: %s: must return a dictionary, this is typically the `qargs'"; luaL_error(l, _E, qss->fpath->str, script_func); } _chk_media_url(l, qs, qss->fpath->str); lua_pop(l, 1); return (QUVI_OK); }
/** Metoda uruchamia skrypt lua, ktory dodaje wszystkie informacje * o spritach. W skrypcie dostepna jest metoda cxx_addSprite * @param void * @return void */ void SpriteManager::loadConfig() { lua_State* L = lua_open(); luaL_openlibs(L); // Rejestracja metody ktora jest wywolywna ze skryptu lua_register( L, "cxx_addSprite", SpriteManager::addSprite ); //Wolanie skryptu if ( luaL_dofile( L, "data/sprite_config.lua" ) != 0 ) { gCritical(lua_tostring( L, -1 )); throw("SpriteManager::loadConfig"); } lua_close(L); }
void LuaScript::OpenScript(const std::string &script){ //If the new script name is valid, open it if (script != ""){ //Close currently open script if one is open Close(); mFile = script; mL = lua_open(); luaL_openlibs(mL); AddLoader(LuaC::LuaScriptLib::requireLib); AddLoader(LuaC::LuaScriptLib::requireScript); luaL_dofile(mL, mFile.c_str()); mOpen = true; //Setup function interface mFcnInterface = LuaC::FunctionInterface(mL, mFile); } }
int main(int argc, char* argv[]) { if(argc != 2) { std::cout << "usage: \n\tNInvoke.exe script_file" << std::endl; return 0; } const char* file = argv[1]; lua_State *L = luaL_newstate(); luaL_openlibs(L); luaopen_ninvoke(L); lua_setglobal(L, "NInvoke"); if(luaL_dofile(L, file) != 0) { std::cerr << lua_tostring(L, -1) << std::endl; } lua_close(L); }
int CCLuaStack::executeScriptFile(const char* filename) { ++m_callFromLua; int nRet = luaL_dofile(m_state, filename); --m_callFromLua; CC_ASSERT(m_callFromLua >= 0); // lua_gc(m_state, LUA_GCCOLLECT, 0); if (nRet != 0) { CCLOG("[LUA ERROR] %s", lua_tostring(m_state, -1)); lua_pop(m_state, 1); return nRet; } return 0; }
D3DXCOLOR LuaScript::GetColourData( char *variable ) { D3DXCOLOR temp; luaL_dofile( L, this->GetPath() ); lua_getglobal(L, variable); if ( lua_istable(L, -1) ) { temp.r = GetField("r"); temp.g = GetField("g"); temp.b = GetField("b"); temp.a = GetField("a"); } return temp; }