def test_load_script(self): state = _luabject.new() self.load_script_to_completion(state, "") # Can load multiple scripts in one state. self.load_script_to_completion(state, "") # Can load a syntactically correct script. state = _luabject.new() self.load_script_to_completion(state, "function foo() prant() end") # Can load multiple syntactically correct scripts in one state. thread = _luabject.new_thread(state) self.load_script_to_completion(state, "function bar() prant() end") # Loading a syntactically incorrect script raises an exception. state = _luabject.new() thread = _luabject.new_thread(state) with self.assertRaises(_luabject.LuaSyntaxError): _luabject.load_script(thread, "1+1") # Can load a syntactically correct script even after a load_script() exception. self.load_script_to_completion(state, "function foo() prant() end") # Loading a syntactically correct script that causes an error works until we evaluate it. state = _luabject.new() thread = _luabject.new_thread(state) _luabject.load_script(thread, "hi()") with self.assertRaises(_luabject.LuaRuntimeError): _luabject.pump_thread(thread) while _luabject.LUA_YIELD == _luabject.thread_status(thread): _luabject.pump_thread(thread) # Can load a syntactically correct script even after a load_script() exception. self.load_script_to_completion(state, "function foo() prant() end")
def load_script(self, script): thread = _luabject.new_thread(self._state) _luabject.load_script(thread, script) _luabject.pump_thread(thread) while _luabject.thread_status(thread) == 1: eventlet.sleep() _luabject.pump_thread(thread)
def load_script_to_completion(self, state, script): thread = _luabject.new_thread(state) _luabject.load_script(thread, script) _luabject.pump_thread(thread) while _luabject.LUA_YIELD == _luabject.thread_status(thread): _luabject.pump_thread(thread)