void PythonEngine::Initialize() { if (!Py_IsInitialized()) { #ifdef _WIN32 Poco::Environment::set("PYTHONHOME", ".\\pymodules"); //_putenv("PYTHONHOME = .\\pymodules"); //loads pymodules/lib/site.py which is the windows //std::cout << "PYTHONHOME SET"; #endif Py_Initialize(); #ifdef _WIN32 //for some reason setting env vars has no effect when running from inside visual studio, //so for VS use, the PYTHONHOME env var had to be set in the project file //.. that is inconvenient, so changed the path manipulation to back here. RunString("import sys; sys.path.append('pymodules/python26_Lib.zip');"); #endif RunString("import sys; sys.path.append('pymodules');"); //XXX change to the c equivalent RunString("import sys; sys.path.append('pymodules/lib');"); // libraries directory RunString("import sys; sys.path.append('pymodules/DLLs');"); // dll directory (PYTHONHOME doesent seem to work to get these) } else { //LogWarning() //XXX add module ref here to be able to do logging std::cout << "Python already initialized in PythonScriptModule init!"; } }
bool SMJS_Plugin::LoadFile(const char* file, bool asGlobal){ HandleScope handle_scope(isolate); char path[512]; #if WIN32 snprintf(path, sizeof(path), "%s\\%s", GetPath(), file); #else snprintf(path, sizeof(path), "%s/%s", GetPath(), file); #endif FILE* fileHandle = fopen(path, "rb"); if(fileHandle == NULL) return false; fseek(fileHandle, 0, SEEK_END); size_t size = ftell(fileHandle); rewind(fileHandle); char* source = new char[size + 1]; for (size_t i = 0; i < size;) { i += fread(&source[i], 1, size - i, fileHandle); } source[size] = '\0'; fclose(fileHandle); bool res = RunString(path, source, asGlobal); delete[] source; return res; }
/// Run the interpreter. void FLLua::run() { LL_INFOS("Lua") << __LINE__ << ": *** THREAD LOOP STARTS HERE ***" << llendl; while(1) { if (!pLuaStack /*|| mError*/ || LLApp::isError() || LLApp::isStopped()) break; //Broked. bool locked=false; mAllowPause=true; //Let FLLUa::CriticalSection() sync with MAIN on first call. // Process Hooks if(mPendingHooks) { lockData(); locked=true; mPendingHooks=false; while(!mQueuedHooks.empty()) //Allow multiple hooks per loop. { // Peek at the top of the stack HookRequest *hr = mQueuedHooks.front(); ExecuteHook(hr); mQueuedHooks.pop(); delete hr; //Say no to memory leaks. } //if(mError)goto endloop; } // Process Macros/Raw Commands if(mPendingCommands) { if(!locked) lockData(); locked=true; mPendingCommands=false; while(!mQueuedCommands.empty()) { // Peek at the top of the stack std::string &hr = mQueuedCommands.front(); //byref. faster. if(FLLua::isMacro(hr)) RunMacro(hr); // Run macro. else RunString(hr); // Run command. mQueuedCommands.pop(); //safe to pop now. //if(mError)goto endloop; } } mAllowPause=true; //endloop: if(locked) unlockData(); //Always. //if(mError)break; yield(); ms_sleep(10); } LL_INFOS("Lua") << __LINE__ << ": *** THREAD EXITING ***" << llendl; }
int c4s_checkstring(const char *script) { return RunString(script, true); }
int c4s_runstring(const char *script) { return RunString(script, false); }
extern "C" int BASE_RunString(lua_State *L) { cLua *lua = CGUIManager::GetInstance()->GetLuaContext(); RunString(lua->GetStringArgument(1)); return 0; }