Ports upstream LUA PRs (#15200)

* 1

* Launch Dreamseeker is the default vscode launch config once again (#68666)

Co-authored-by: William Wallace <me@wiox.me>
This commit is contained in:
Zonespace
2022-07-27 15:14:22 -07:00
committed by GitHub
parent b2d2a90916
commit a1aee41c68
10 changed files with 190 additions and 86 deletions
+16 -6
View File
@@ -4,20 +4,30 @@
/proc/wrap_lua_datum_proc_call(datum/thing_to_call, proc_name, list/arguments)
if(!usr)
usr = GLOB.lua_usr
var/ret
if(usr)
SSlua.gc_guard = WrapAdminProcCall(thing_to_call, proc_name, arguments)
ret = WrapAdminProcCall(thing_to_call, proc_name, arguments)
else
SSlua.gc_guard = HandleUserlessProcCall("lua", thing_to_call, proc_name, arguments)
return SSlua.gc_guard
ret = HandleUserlessProcCall("lua", thing_to_call, proc_name, arguments)
if(isdatum(ret))
SSlua.gc_guard = ret
var/datum/ret_datum = ret
ret_datum.RegisterSignal(ret_datum, COMSIG_PARENT_QDELETING, /datum.proc/lua_reference_cleanup, override = TRUE)
return ret
/proc/wrap_lua_global_proc_call(proc_name, list/arguments)
if(!usr)
usr = GLOB.lua_usr
var/ret
if(usr)
SSlua.gc_guard = WrapAdminProcCall(GLOBAL_PROC, proc_name, arguments)
ret = WrapAdminProcCall(GLOBAL_PROC, proc_name, arguments)
else
SSlua.gc_guard = HandleUserlessProcCall("lua", GLOBAL_PROC, proc_name, arguments)
return SSlua.gc_guard
ret = HandleUserlessProcCall("lua", GLOBAL_PROC, proc_name, arguments)
if(isdatum(ret))
SSlua.gc_guard = ret
var/datum/ret_datum = ret
ret_datum.RegisterSignal(ret_datum, COMSIG_PARENT_QDELETING, /datum.proc/lua_reference_cleanup, override = TRUE)
return ret
/proc/wrap_lua_print(state_id, list/arguments)
var/datum/lua_state/target_state
+14
View File
@@ -30,3 +30,17 @@
#undef PROMISE_PENDING
#undef PROMISE_RESOLVED
#undef PROMISE_REJECTED
/**
* When a datum is created from lua, it gets held in `SSlua.gc_guard`, and later,
* in the calling state datum's `var/list/references`, just in case it would be garbage
* collected due to there not being any references that BYOND recognizes. To avoid harddels,
* we register this proc as a signal handler any time a DM function called from lua returns
* a datum.
*/
/datum/proc/lua_reference_cleanup()
SIGNAL_HANDLER
if(SSlua.gc_guard == src)
SSlua.gc_guard = null
for(var/datum/lua_state/state in SSlua.states)
state.references -= src
@@ -85,6 +85,8 @@
switch(action)
if("newState")
var/state_name = params["name"]
if(!length(state_name))
return TRUE
var/datum/lua_state/new_state = new(state_name)
SSlua.states += new_state
LAZYREMOVEASSOC(SSlua.editors, "\ref[current_state]", src)
@@ -170,10 +172,16 @@
var/log_entry_index = params["entryIndex"]
var/list/log_entry = current_state.log[log_entry_index]
var/thing_to_debug = traverse_list(params["tableIndices"], log_entry["param"])
if(isweakref(thing_to_debug))
var/datum/weakref/ref = thing_to_debug
thing_to_debug = ref.resolve()
INVOKE_ASYNC(usr.client, /client.proc/debug_variables, thing_to_debug)
return FALSE
if("vvGlobal")
var/thing_to_debug = traverse_list(params["indices"], current_state.globals)
if(isweakref(thing_to_debug))
var/datum/weakref/ref = thing_to_debug
thing_to_debug = ref.resolve()
INVOKE_ASYNC(usr.client, /client.proc/debug_variables, thing_to_debug)
return FALSE
if("clearArgs")
+8 -2
View File
@@ -38,6 +38,8 @@ GLOBAL_PROTECT(lua_usr)
SSlua.sleeps += src
/datum/lua_state/proc/log_result(result, verbose = TRUE)
if(!islist(result))
return
if(!verbose && result["status"] != "errored" && result["status"] != "bad return" \
&& !(result["name"] == "input" && (result["status"] == "finished" || length(result["param"]))))
return
@@ -55,7 +57,7 @@ GLOBAL_PROTECT(lua_usr)
append_to_log = FALSE
break
if(append_to_log)
log += list(result)
log += list(weakrefify_list(result))
/datum/lua_state/proc/load_script(script)
GLOB.IsLuaCall = TRUE
@@ -91,6 +93,10 @@ GLOBAL_PROTECT(lua_usr)
if(istext(result))
result = list("status" = "errored", "param" = result, "name" = islist(function) ? jointext(function, ".") : function)
check_if_slept(result)
var/list/editor_list = LAZYACCESS(SSlua.editors, "\ref[src]")
if(editor_list)
for(var/datum/lua_editor/editor in editor_list)
SStgui.update_uis(editor)
return result
/datum/lua_state/proc/call_function_return_first(function, ...)
@@ -126,7 +132,7 @@ GLOBAL_PROTECT(lua_usr)
return result
/datum/lua_state/proc/get_globals()
globals = __lua_get_globals(internal_id)
globals = weakrefify_list(__lua_get_globals(internal_id))
/datum/lua_state/proc/get_tasks()
return __lua_get_tasks(internal_id)