void Script::setState(lua_State* pState){ if(pState==NULL){ m_pState = luaL_newstate(); lua_pop( m_pState, luaopen_base( m_pState ) ); lua_pop( m_pState, luaopen_math( m_pState ) ); lua_pop( m_pState, 1 ); // Save a pointer to the thread Manager object in the global table // using the new thread script vm pointer as a key. lua_pushlightuserdata( m_pState, m_pState ); lua_pushlightuserdata( m_pState, this ); lua_settable( m_pState, LUA_GLOBALSINDEX ); }else{ m_pState = pState; } // open standard libs luaL_openlibs( m_pState ); lua_settop( m_pState, 0 ); // open lua socket libs luaopen_socket_core(m_pState); luaopen_mime_core(m_pState); luaopen_ssl_context(m_pState); luaopen_ssl_x509(m_pState); luaopen_ssl_core(m_pState); // open luasql libs luaopen_luasql_mysql(m_pState); // open luahiredis libs luaopen_hiredis(m_pState); // open self define c libs tolua_hivenet_open(m_pState); }
int _jason_openlibs(lua_State* L) { luaopen_socket_core(L); /* Opening the Socket library */ luaopen_mime_core(L); /* Opening the Socket library mime support*/ luaopen_lfs(L); /* Opening the Lua Filesystem library */ luaopen_rings(L); /* Opening the Rings library */ luaopen_md5_core(L); /* Opening the MD5 library */ luaopen_base64(L); /* Opening the Base64 library */ luaopen_des56(L); /* Opening the DES56 library */ luaopen_luasystray(L); /* Opening the LuaSysTray library */ luaopen_luamobile(L); /* Opening the LuaMobile library */ /* Opening the LPeg library */ lua_pushcclosure(L, luaopen_lpeg, 0); lua_pushstring(L, "lpeg"); lua_call(L, 1, 0); }
int main(int argc, char ** argv) { setExecutablePath(argv[0]); lua_State *L = lua_open(); luaL_openlibs(L); #if USE_IUP iuplua_open(L); cdlua_open(L); cdluaiup_open(L); iupkey_open(L); iupimlua_open(L); IupImageLibOpen (); iupcontrolslua_open(L); imlua_open(L); imlua_open_process(L); #endif luaopen_pack(L); luaopen_lfs(L); luaopen_marshal(L); luaopen_mime_core(L); luaopen_socket_core(L); pdfdoc_register(L); pdfpage_register(L); clipboard_register(L); luaopen_system(L); luaopen_compare(L); #if _DEBUG lua_pushboolean(L, true); lua_setfield(L, LUA_GLOBALSINDEX, "_DEBUG"); #endif char luaFile[512] = ""; char playlistFile[512] = ""; int beginIndex = 1; if (argc > 1) { int strl = strlen(argv[1]); bool isLuaFile = strcmp(&argv[1][strl-4], ".lua") == 0; if (isLuaFile) { beginIndex = 2; strcpy_s(luaFile, sizeof(luaFile), argv[1]); } else if (strcmp(&argv[1][strl-5], ".sing") == 0 || strcmp(&argv[1][strl-4], ".m3u") == 0 || strcmp(&argv[1][strl-4], ".txt") == 0) { } } if (!luaFile[0]) { lua_pushboolean(L, true); lua_setfield(L, LUA_GLOBALSINDEX, "APPLOADED"); const char* execPath = getExecutablePath(); sprintf_s(luaFile, sizeof(luaFile), "%s\\%s", execPath, "main.lua"); } int temp_int = luaL_loadfile(L,luaFile); int returnval = 0; if (temp_int) { const char *error = lua_tostring(L, -1); printf("Error in file: \"%s\"\n", luaFile); printf("%s\n", error); returnval = 1; } else { const char *error; for (int i = beginIndex; i < argc; i++) lua_pushstring(L, argv[i]); if (docall(L,argc-beginIndex,0)) { error = lua_tostring(L, -1); if (error) std::cout << error; returnval = 1; } } close(L); return returnval; }