provide script name in errors

This commit is contained in:
Face
2025-09-10 17:19:03 +03:00
parent 6cf5d2f19c
commit e49f9887f0
4 changed files with 21 additions and 13 deletions

View File

@@ -56,11 +56,12 @@ func stop_lua_thread():
lua_thread.wait_to_finish()
lua_thread = null
func execute_script_async(script_code: String):
func execute_script_async(script_code: String, chunk_name: String = "dostring"):
queue_mutex.lock()
command_queue.append({
"type": "execute_script",
"code": script_code
"code": script_code,
"chunk_name": chunk_name
})
queue_mutex.unlock()
thread_semaphore.post()
@@ -143,21 +144,28 @@ func _process_command_queue():
for command in commands_to_process:
match command.type:
"execute_script":
_execute_script_in_thread(command.code)
_execute_script_in_thread(command.code, command.get("chunk_name", "dostring"))
"execute_callback":
_execute_callback_in_thread(command.callback_ref, command.args)
"execute_timeout":
_execute_timeout_in_thread(command.timeout_id)
func _execute_script_in_thread(script_code: String):
func _execute_script_in_thread(script_code: String, chunk_name: String = "dostring"):
if not lua_vm:
call_deferred("_emit_script_error", "Lua VM not initialized")
return
var result = lua_vm.lua_dostring(script_code)
# Use load_string with custom chunk name, then lua_pcall
var load_result = lua_vm.load_string(script_code, chunk_name)
if result == lua_vm.LUA_OK:
call_deferred("_emit_script_completed", {"success": true})
if load_result == lua_vm.LUA_OK:
var call_result = lua_vm.lua_pcall(0, 0, 0)
if call_result == lua_vm.LUA_OK:
call_deferred("_emit_script_completed", {"success": true})
else:
var error_msg = lua_vm.lua_tostring(-1)
lua_vm.lua_pop(1)
call_deferred("_emit_script_error", error_msg)
else:
var error_msg = lua_vm.lua_tostring(-1)
lua_vm.lua_pop(1)