/*********************************************************** constructor ***********************************************************/ LuaHandlerBase::LuaHandlerBase() : m_creatingthread(-1) { try { // Create a new lua state m_LuaState = lua_open(); // Connect LuaBind to this lua state luabind::open(m_LuaState); //open standard libs luaopen_base(m_LuaState); luaopen_table(m_LuaState); luaopen_string(m_LuaState); luaopen_math(m_LuaState); luaopen_debug(m_LuaState); //luaopen_package(m_LuaState); //luaL_openlibs(m_LuaState); } catch(const std::exception &error) { LogHandler::getInstance()->LogToFile(std::string("Exception initializing LUA for base lua: ") + error.what(), 0); } }
int main(int argc, char** argv) { for (int n=1; n<argc; ++n) { const char* file=argv[n]; lua_State *L = lua_open(); luaopen_io(L); // provides io.* luaopen_base(L); luaopen_table(L); luaopen_math(L); // luaopen_loadlib(L); // luaopen_loadlib(L); std::cerr << "-- Loading file:" << file << std::endl; int s = luaL_loadfile(L, file); if (s==0) { // execute Lua program s = lua_pcall(L, 0, LUA_MULTRET, 0); } report_errors(L, s); lua_close(L); std::cerr << std::endl; } return 0; }
int luaInit() { luaFree(); state.lua = lua_open(); if (!state.lua) { conAdd(LERR, "Error loading LUA"); return 0; } luaL_openlibs(state.lua); luaopen_base(state.lua); luaopen_table(state.lua); luaopen_string(state.lua); luaopen_math(state.lua); #define AddFunction(a,b) lua_pushcfunction(state.lua, b); lua_setglobal(state.lua, a); AddFunction("particle", luag_spawn) AddFunction("log", luag_log) AddFunction("load", luag_load); return 1; }
void LuaLibrary::VLoadCoreModule( const unsigned int selectedModule) { CoreModules coreModule = static_cast<CoreModules>(selectedModule); switch(coreModule) { case LuaLibrary::CoreModules::Base: luaopen_base(m_pLuaState); break; case LuaLibrary::CoreModules::Debug: luaopen_debug(m_pLuaState); break; case LuaLibrary::CoreModules::Math: luaopen_math(m_pLuaState); break; case LuaLibrary::CoreModules::Os: luaopen_os(m_pLuaState); break; case LuaLibrary::CoreModules::String: luaopen_string(m_pLuaState); break; case LuaLibrary::CoreModules::Table: luaopen_table(m_pLuaState); break; } }
void LuaState::Init( bool initStandardLibrary ) { // Register some basic functions with Lua. if (initStandardLibrary) { // A "bug" in Lua 5.01 causes stack entries to be left behind. LuaAutoBlock autoBlock(this); luaopen_base(m_state); luaopen_table( m_state ); luaopen_io(m_state); luaopen_string(m_state); luaopen_wstring(m_state); luaopen_math(m_state); luaopen_debug(m_state); #ifndef _WIN32_WCE luaopen_loadlib(m_state); #endif _WIN32_WCE ScriptFunctionsRegister( this ); GetGlobals().Register("LuaDumpGlobals", LS_LuaDumpGlobals); GetGlobals().Register("LuaDumpObject", LS_LuaDumpObject); GetGlobals().Register("LuaDumpFile", LS_LuaDumpFile); } GetGlobals().Register("LOG", LS_LOG); GetGlobals().Register("_ALERT", LS_LOG); lua_atpanic( m_state, FatalError ); }
//============================================================================ // bool CLuaVirtualMachine::InitialiseVM //--------------------------------------------------------------------------- // Initialises the VM, open lua, makes sure things are OK // // Parameter Dir Description // --------- --- ----------- // None. // // Return // ------ // Success. // //============================================================================ bool CLuaVirtualMachine::InitialiseVM (void) { // Open Lua! if (Ok ()) DestroyVM (); m_pState = lua_open (); if (m_pState) { m_fIsOk = true; // Load util libs into lua luaopen_base (m_pState); luaopen_table (m_pState); luaopen_string (m_pState); luaopen_math (m_pState); luaopen_debug (m_pState); //luaopen_io (m_pState); //luaopen_loadlib (m_pState); // setup global printing (trace) lua_pushcclosure (m_pState, printMessage, 0); lua_setglobal (m_pState, "trace"); lua_atpanic (m_pState, (lua_CFunction) CLuaVirtualMachine::Panic); return true; } return false; }
int main(void) { char buff[256]; char buf[256]; int error; lua_State *L = luaL_newstate(); luaL_openlibs(L); luaopen_base(L); /* opens the basic library */ luaopen_table(L); /* opens the table library */ luaopen_io(L); /* opens the I/O library */ luaopen_string(L); /* opens the string lib. */ luaopen_math(L); /* opens the math lib. */ char s1[] = "lzkx"; char s2 = "zny"; printf("input: ddd\n"); sacnf_s(); while (fgets(buff, sizeof(buff), stdin) != NULL) { sprintf_s(buf,256, "print ( %s)", buff,256); error = luaL_loadbuffer(L, buf, strlen(buf), "line") || lua_pcall(L, 0, 0, 0); if (error) { fprintf(stderr, "%s", lua_tostring(L, -1)); lua_pop(L, 1); /* pop error message from the stack */ } } lua_close(L); return 0; }
int ltapi_libraries_load( lua_State * L ) { /* load required library and discard any possible results remaining at * the stack */ luaopen_base( L ); lua_settop( L, 0 ); luaopen_table( L ); lua_settop( L, 0 ); luaopen_io( L ); lua_settop( L, 0 ); luaopen_string( L ); lua_settop( L, 0 ); luaopen_math( L ); lua_settop( L, 0 ); luaopen_debug( L ); lua_settop( L, 0 ); luaopen_loadlib( L ); lua_settop( L, 0 ); return 0; }
bool P3DPlugLuaRunScript(const char *FileName, const P3DPlantModel*PlantModel) { lua_State *State; SetCLocale(); State = lua_open(); if (State != NULL) { #if NGP_LUA_VER > 50 luaL_openlibs(State); #else luaopen_base(State); luaopen_table(State); luaopen_io(State); luaopen_string(State); luaopen_math(State); #endif P3DPlugLuaRegisterHLI(State); P3DPlugLuaRegisterUI(State); P3DPlugLuaRegisterFS(State); P3DPlugLuaRegisterExportPrefs(State,P3DApp::GetApp()->GetExport3DPrefs()); P3DPlugLuaRegisterModel(State,"PlantModel",PlantModel); lua_register(State,"GetTextureFileName",GetTextureFileName); lua_register(State,"GetCurrentLOD",GetCurrentLOD); lua_register(State,"GetDerivedFileName",GetDerivedFileName); if (luaL_loadfile(State,FileName) || lua_pcall(State,0,0,0)) { if (lua_isstring(State,-1)) { DisplayErrorMessage(wxString(lua_tostring(State,-1),wxConvUTF8)); } else { DisplayErrorMessage(wxT("Script error: (undefined)")); } } lua_close(State); RestoreLocale(); return(true); } else { DisplayErrorMessage(wxT("Unable to initialize Lua environment")); RestoreLocale(); return(false); } }
void resetProgram(void) { char *initscript = "keyboard={}; keyboard['pressed']={};" "mouse={}; mouse['pressed']={};" "sprites={}"; l81.epoch = 0; if (l81.L) lua_close(l81.L); l81.L = lua_open(); luaopen_base(l81.L); luaopen_table(l81.L); luaopen_string(l81.L); luaopen_math(l81.L); luaopen_debug(l81.L); setNumber("WIDTH",l81.width); setNumber("HEIGHT",l81.height); luaL_loadbuffer(l81.L,initscript,strlen(initscript),"initscript"); lua_pcall(l81.L,0,0,0); /* Make sure that mouse parameters make sense even before the first * mouse event captured by SDL */ setTableFieldNumber("mouse","x",0); setTableFieldNumber("mouse","y",0); setTableFieldNumber("mouse","xrel",0); setTableFieldNumber("mouse","yrel",0); /* Register API */ lua_pushcfunction(l81.L,fillBinding); lua_setglobal(l81.L,"fill"); lua_pushcfunction(l81.L,filledBinding); lua_setglobal(l81.L,"filled"); lua_pushcfunction(l81.L,rectBinding); lua_setglobal(l81.L,"rect"); lua_pushcfunction(l81.L,ellipseBinding); lua_setglobal(l81.L,"ellipse"); lua_pushcfunction(l81.L,backgroundBinding); lua_setglobal(l81.L,"background"); lua_pushcfunction(l81.L,triangleBinding); lua_setglobal(l81.L,"triangle"); lua_pushcfunction(l81.L,lineBinding); lua_setglobal(l81.L,"line"); lua_pushcfunction(l81.L,textBinding); lua_setglobal(l81.L,"text"); lua_pushcfunction(l81.L,setFPSBinding); lua_setglobal(l81.L,"setFPS"); lua_pushcfunction(l81.L,getpixelBinding); lua_setglobal(l81.L,"getpixel"); lua_pushcfunction(l81.L,spriteBinding); lua_setglobal(l81.L,"sprite"); lua_pushcfunction(l81.L,polygonBinding); lua_setglobal(l81.L,"polygon"); initSpriteEngine(l81.L); /* Start with a black screen */ fillBackground(l81.fb,0,0,0); }
void scripting_Init() { L = lua_open(); luaopen_base(L); luaopen_table(L); luaopen_string(L); luaopen_io(L); // init_c_interface(L); }
static void open_libs(lua_State *L) { luaopen_io(L); luaopen_base(L); luaopen_table(L); luaopen_string(L); luaopen_math(L); // luaopen_loadlib(L); }
int open_table() { if (L) { luaopen_table(L); return 0; } return -1; }
/************************************************************************* Constructor (creates Lua state) *************************************************************************/ LuaScriptModule::LuaScriptModule(lua_State* state) : d_ownsState(state == 0), d_state(state), d_errFuncIndex(LUA_NOREF), d_activeErrFuncIndex(LUA_NOREF) { // initialise and create a lua_State if one was not provided if (!d_state) { #if CEGUI_LUA_VER >= 51 static const luaL_Reg lualibs[] = { {"", luaopen_base}, {LUA_LOADLIBNAME, luaopen_package}, {LUA_TABLIBNAME, luaopen_table}, {LUA_IOLIBNAME, luaopen_io}, {LUA_OSLIBNAME, luaopen_os}, {LUA_STRLIBNAME, luaopen_string}, {LUA_MATHLIBNAME, luaopen_math}, #if defined(DEBUG) || defined (_DEBUG) {LUA_DBLIBNAME, luaopen_debug}, #endif {0, 0} }; #endif /* CEGUI_LUA_VER >= 51 */ // create a lua state d_ownsState = true; #if LUA_VERSION_NUM > 501 d_state = luaL_newstate(); #else d_state = lua_open(); #endif // init all standard libraries #if CEGUI_LUA_VER >= 51 const luaL_Reg *lib = lualibs; for (; lib->func; lib++) { lua_pushcfunction(d_state, lib->func); lua_pushstring(d_state, lib->name); lua_call(d_state, 1, 0); } #else /* CEGUI_LUA_VER >= 51 */ luaopen_base(d_state); luaopen_io(d_state); luaopen_string(d_state); luaopen_table(d_state); luaopen_math(d_state); #if defined(DEBUG) || defined (_DEBUG) luaopen_debug(d_state); #endif #endif /* CEGUI_LUA_VER >= 51 */ } setModuleIdentifierString(); }
void LuaPhysicsSetup::initPhysics() { m_guiHelper->setUpAxis(upaxis); const char* prefix[]={"./","./data/","../data/","../../data/","../../../data/","../../../../data/"}; int numPrefixes = sizeof(prefix)/sizeof(const char*); char relativeFileName[1024]; FILE* f=0; int result = 0; for (int i=0;!f && i<numPrefixes;i++) { sprintf(relativeFileName,"%s%s",prefix[i],sLuaFileName); f = fopen(relativeFileName,"rb"); } if (f) { fclose(f); lua_State *L = luaL_newstate(); luaopen_io(L); // provides io.* luaopen_base(L); luaopen_table(L); luaopen_string(L); luaopen_math(L); //luaopen_package(L); luaL_openlibs(L); // make my_function() available to Lua programs lua_register(L, "createDefaultDynamicsWorld", gCreateDefaultDynamicsWorld); lua_register(L, "deleteDynamicsWorld", gDeleteDynamicsWorld); lua_register(L, "createCubeShape", gCreateCubeShape); lua_register(L, "createSphereShape", gCreateSphereShape); lua_register(L, "loadMultiBodyFromUrdf",gLoadMultiBodyFromUrdf); lua_register(L, "createRigidBody", gCreateRigidBody); lua_register(L, "setBodyPosition", gSetBodyPosition); lua_register(L, "setBodyOrientation", gSetBodyOrientation); int s = luaL_loadfile(L, relativeFileName); if ( s==0 ) { // execute Lua program s = lua_pcall(L, 0, LUA_MULTRET, 0); } report_errors(L, s); lua_close(L); } else { b3Error("Cannot find Lua file%s\n",sLuaFileName); } }
static void open_std_libs(lua_State *l) { luaopen_base(l); lua_settop(l, 0); luaopen_table(l); lua_settop(l, 0); luaopen_io(l); lua_settop(l, 0); luaopen_string(l); lua_settop(l, 0); luaopen_debug(l); lua_settop(l, 0); luaopen_math(l); lua_settop(l, 0); }
LuaInterfaceBase::LuaInterfaceBase(): lua(kaguya::NoLoadLib()) { luaopen_base(lua.state()); luaopen_package(lua.state()); luaopen_string(lua.state()); luaopen_table(lua.state()); luaopen_math(lua.state()); Register(lua); }
void lua_context::init() { // initialize Lua state_.reset(luaL_newstate(), [](lua_State* L) { lua_close(L); }); // load various Lua libraries luaopen_base(context_ptr()); luaopen_string(context_ptr()); luaopen_table(context_ptr()); luaopen_math(context_ptr()); luaopen_io(context_ptr()); luaopen_debug(context_ptr()); luaL_openlibs(context_ptr()); luaL_newmetatable(context_ptr(), function_str); luaL_setfuncs(context_ptr(), gFFLFunctions, 0); luaL_newmetatable(context_ptr(), callable_str); luaL_setfuncs(context_ptr(), gCallableFunctions, 0); luaL_newmetatable(context_ptr(), callable_function_str); luaL_setfuncs(context_ptr(), gFFLCallableFunctions, 0); luaL_newmetatable(context_ptr(), lib_functions_str); luaL_setfuncs(context_ptr(), gLibMetaFunctions, 0); push_anura_table(context_ptr()); /*dostring( "local lvl = Anura.level()\n" "print(lvl.id, lvl.music_volume, lvl.in_editor)\n" "Anura.debug('abcd')\n" "Anura.eval('debug(map(range(10),value))')\n" "local camera = lvl.camera\n" "print('Camera speed: ' .. camera.speed)\n" "for n = 1, 10 do\n" " camera.speed = n\n" " print('Camera speed: ' .. camera.speed)\n" "end\n" "lvl.player:debug_rect(lvl.player.mid_x-50, lvl.player.mid_y-50, 100, 100)\n" //"for i,v in ipairs(lvl.active_chars) do\n" //"for i,v in ipairs(Anura.eval('range(10)')) do\n" "local mm = Anura.eval('{q(a):1,q(b):2}')\n" //"print(mm.a)\n" "for i,v in pairs(mm) do\n" " print(i, v)\n" "end\n" );*/ /*dostring("local me = Anura.me\n" "print(me.speed)", level::current().camera().get() );*/ }
void Script :: setupBindings() { assert(!m_pState); m_pState = lua_open(); luaopen_base(m_pState); luaopen_table(m_pState); //luaopen_io(m_pState); luaopen_string(m_pState); luaopen_math(m_pState); //luaopen_libs(m_pState); }
extern P3DGMeshData *P3DPlugLuaRunGMeshGenerator (const char *FileName) { lua_State *State; P3DGMeshData *Result = 0; SetCLocale(); State = lua_open(); if (State != NULL) { #if NGP_LUA_VER > 50 luaL_openlibs(State); #else luaopen_base(State); luaopen_table(State); luaopen_io(State); luaopen_string(State); luaopen_math(State); #endif P3DPlugLuaRegisterUI(State); if (luaL_loadfile(State,FileName) || lua_pcall(State,0,1,0)) { if (lua_isstring(State,-1)) { DisplayErrorMessage(wxString(lua_tostring(State,-1),wxConvUTF8)); } else { DisplayErrorMessage(wxT("Script error: (undefined)")); } } else { Result = CreateGMeshDataFromLuaTable(State); } lua_close(State); RestoreLocale(); } else { DisplayErrorMessage(wxT("Unable to initialize Lua environment")); RestoreLocale(); } return(Result); }
/* void luavm_regs(void*vm) { int gc(lua_State*vm) { return 0; } int ts(lua_State*vm) { lua_pushstring(L,"pd"); return 1; } lua_newtable(vm); int methods=lua_gettop(vm); lua_newtable(vm,"pd"); int metatable=lua_gettop(vm); lua_pushstring(vm,"pd"); lua_pushvalue(vm,methods); lua_settable(vm,LUA_GLOBALSINDEX); lua_pushliteral(vm,"__metatable"); lua_pushvalue(vm,methods); lua_settable(vm,metatable); lua_pushliteral(vm,"__index"); lua_pushvalue(vm,methods); lua_settable(vm,metatable); lua_pushliteral(vm,"__tostring"); lua_pushvalue(vm,methods); lua_settable(vm,metatable); } */ void luavm_init(luavm*const ins) { luaopen_base(ins->vm); luaopen_table(ins->vm); //luaopen_io(ins->vm); luaopen_string(ins->vm); luaopen_math(ins->vm); //luaopen_debug(ins->vm); lua_register(ins->vm,"print",print); lua_settop(ins->vm,0); }
interp_t *interp_new(int flags, int ipcfd) { interp_t *interp = NULL; lua_State *L = NULL; static const luaL_Reg ipcfuncs[] = { {"ready", bipc_ready}, {"connect", bipc_connect}, {NULL, NULL}, }; L = luaL_newstate(); if (L == NULL) { return NULL; } luaopen_base(L); luaopen_coroutine(L); luaopen_table(L); luaopen_string(L); #if (LUA_VERSION_NUM >= 503) luaopen_utf8(L); #endif luaopen_bit32(L); luaopen_math(L); luaopen_debug(L); luaopen_package(L); /* not opened: io, os */ /* create a userdata object that represents the interpreter */ interp = (interp_t*)lua_newuserdata(L, sizeof(interp_t)); if (interp == NULL) { lua_close(L); return NULL; } memset(interp, 0, sizeof(interp_t)); interp->ipcfd = ipcfd; interp->L = L; /* Build a metatable with the methods for our userdata object. * Assign the userdata object to BIRK_IPCNAME */ luaL_newmetatable(L, BIRK_IPCNAME); lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); luaL_setfuncs(L, ipcfuncs, 0); lua_setmetatable(L, -2); lua_setglobal(L, BIRK_IPCNAME); if ((flags & INTERPF_LOADBIRK) && interp_load(interp, "birk") != BIRK_OK) { /* error message is set, caller should check it on return */ return interp; } return interp; }
void lua_init(void) { lua_State *L = luaL_newstate(); luaopen_base(L); luaopen_table(L); luaopen_string(L); luaopen_math(L); lua_close(L); lua_script_loader.data = L; resource_loader_register(&lua_script_loader); }
cLua::cLua() { m_pErrorHandler = NULL; m_pScriptContext = lua_open(); luaopen_base(m_pScriptContext); luaopen_io(m_pScriptContext); luaopen_string(m_pScriptContext); luaopen_math(m_pScriptContext); luaopen_debug(m_pScriptContext); luaopen_table(m_pScriptContext); }
Script::Script() { lua_state_ = luaL_newstate(); luaL_openlibs(lua_state_); luaopen_base(lua_state_); luaopen_table(lua_state_); luaopen_math(lua_state_); luaopen_string(lua_state_); registerEventFunctions(); }
CLuaState::CLuaState() { m_LuaState = luaL_newstate(); luaopen_base(m_LuaState); luaopen_string(m_LuaState); luaopen_table(m_LuaState); CLuaState** l_ppThis = (CLuaState**)lua_newuserdata(m_LuaState, sizeof(CLuaState*)); *l_ppThis = this; lua_setglobal(m_LuaState, LUA_STATE_OBJECT_LUA_GLOBAL_IDENTIFIER); }
lua_State* LuaWorld::getState() { if(GlobalState==NULL) { GlobalState = luaL_newstate(); luaopen_io(GlobalState); luaopen_base(GlobalState); luaopen_table(GlobalState); luaopen_string(GlobalState); luaopen_math(GlobalState); luaL_openlibs(GlobalState); } return GlobalState; }
LuaScript::LuaScript() { m_LuaState = lua_open(); if( m_LuaState ) { // инициализация стандартных библиотечных функции lua luaopen_base( m_LuaState ); luaopen_table( m_LuaState ); luaopen_string( m_LuaState ); luaopen_math( m_LuaState ); luaopen_os( m_LuaState ); } else Log( "Error Initializing Lua" ); }
void Interpreter::initialize(Renderer *renderer) { interpreter = this; mRenderer = renderer; L = lua_open(); printf("opening lua"); //luaopen_io(L); luaopen_base(L); luaopen_table(L); luaopen_string(L); luaopen_math(L); //luaopen_loadlib(L); printf("registering newIsland"); lua_register(L, "newIsland", func_newIsland); lua_register(L, "clearIslands", func_clearIslands); }
void LuaManager::Init() { luaState = lua_open(); assert(luaState); luaopen_base (luaState); luaopen_table (luaState); luaopen_string (luaState); luaopen_math (luaState); luaopen_debug (luaState); luaL_openlibs(luaState); toluafix_open(luaState); tolua_attempt_open(luaState); SetLuaLoaderFunc(LuaLoader); LuaOpenLibName(); }