TG Upstream Part 1

3591 individual conflicts

Update build.js

Update install_node.sh

Update byond.js

oh my fucking god

hat

slow

huh

holy shit

we all fall down

2 more I missed

2900 individual conflicts

2700 Individual conflicts

replaces yarn file with tg version, bumping us down to 2200-ish

Down to 2000 individual conflicts

140 down

mmm

aaaaaaaaaaaaaaaaaaa

not yt

575

soon

900 individual conflicts

600 individual conflicts, 121 file conflicts

im not okay

160 across 19 files

29 in 4 files

0 conflicts, compiletime fix time

some minor incap stuff

missed ticks

weird dupe definition stuff

missed ticks 2

incap fixes

undefs and pie fix

Radio update and some extra minor stuff

returns a single override

no more dupe definitions, 175 compiletime errors

Unticked file fix

sound and emote stuff

honk and more radio stuff
This commit is contained in:
Waterpig
2024-09-08 10:49:28 +02:00
committed by Majkl-J
parent 67e8dba34a
commit bb70889f6e
1578 changed files with 384 additions and 52713 deletions
-265
View File
@@ -1,152 +1,3 @@
<<<<<<< HEAD
# Auxlua
---
## Datums
DM datums are treated as lua userdata, and can be stored in fields. Due to fundamental limitations in lua, userdata is inherently truthy. Since datum userdata can correspond to a deleted datum, which would evaluate to `null` in DM, the function [`datum:is_null()`](#datumisnull) is provided to offer a truthiness test consistent with DM.
Keep in mind that BYOND can't see that a datum is referenced in a lua field, and will garbage collect it if it is not referenced anywhere in DM.
### datum:get_var(var)
Equivalent to DM's `datum.var`
### datum:set_var(var, value)
Equivalent to DM's `datum.var = value`
### datum:call_proc(procName, ...)
Equivalent to DM's `datum.procName(...)`
### datum:is_null()
This function is used to evaluate the truthiness of a DM var. The lua statement `if datum:is_null() then` is equivalent to the DM statement `if(datum)`.
### datum.vars
Returns a userdatum that allows you to access and modifiy the vars of a DM datum by index. `datum.vars.foo` is equivalent to `datum:get_var("foo")`, while `datum.vars.foo = bar` is equivalent to `datum:set_var("foo", bar)`
---
## Lists
In order to allow lists to be modified in-place across the DM-to-lua language barrier, lists are treated as userdata. Whenever running code that expects a DM value, auxlua will attempt to convert tables into lists.
List references are subject to the same limitations as datum userdata, but you are less likely to encounter these limitations for regular lists.
Some lists (`vars`, `contents`, `overlays`, `underlays`, `vis_contents`, and `vis_locs`) are inherently attached to datums, and as such, their corresponding userdata contains a weak reference to the containing datum. Use [`list:is_null`](#listisnull) to validate these types of lists.
### list.len
Equivalent to DM's `list.len`
### list:get(index)
Equivalent to DM's `list[index]`
### list:set(index, value)
Equivalent to DM's `list[index] = value`
### list:add(value)
Equivalent to DM's `list.Add(value)`
### list:remove(value)
Equivalent to DM's `list.Remove(value)`
### list:to_table()
Converts a DM list into a lua table.
### list:of_type(type_path)
Will extract only values of type `type_path`.
### list:is_null()
A similar truthiness test to [`datum:is_null()`](#datumisnull). This function only has the possibility of returning `false` for lists that are inherently attached to a datum (`vars`, `contents`, `overlays`, `underlays`, `vis_contents`, and `vis_locs`).
### list.entries
Returns a userdatum that allows you to access and modifiy the entries of the list by index. `list.entries.foo` is equivalent to `list:get("foo")`, while `list.entries.foo = bar` is equivalent to `list:set("foo", bar)`
---
## The dm table
The `dm` table consists of the basic hooks into the DM language.
### dm.state_id
The address of the lua state in memory. This is a copy of the internal value used by auxlua to locate the lua state in a global hash map. `state_id` is a registry value that is indirectly obtained using the `dm` table's `__index` metamethod.
### dm.global_proc(proc, ...)
Calls the global proc `/proc/[proc]` with `...` as its arguments.
### dm.world
A reference to DM's `world`, in the form of datum userdata. This reference is always valid, since `world` always exists.
Due to limitations inherent in the wrapper functions used on tgstation, `world:set_var` and `world:call_proc` will raise an error.
### dm.global_vars
A reference to DM's `global`, in the form of datum userdata. Subject to the same limitations as `dm.world`
### dm.usr
A weak reference to DM's `usr`. As a rule of thumb, this is a reference to the mob of the client who triggered the chain of procs leading to the execution of Lua code. The following is a list of what `usr` is for the most common ways of executing Lua code:
- For resumes and awakens, which are generally executed by the MC, `usr` is (most likely) null.
- `SS13.wait` queues a resume, which gets executed by the MC. Therefore, `usr` is null after `SS13.wait` finishes.
- For chunk loads, `usr` is generally the current mob of the admin that loaded that chunk.
- For function calls done from the Lua editor, `usr` is the current mob of the admin calling the function.
- `SS13.register_signal` creates a `/datum/callback` that gets executed by the `SEND_SIGNAL` macro for the corresponding signal. As such, `usr` is the mob that triggered the chain of procs leading to the invocation of `SEND_SIGNAL`.
---
## Execution Limit
In order to prevent freezing the server with infinite loops, auxlua enforces an execution limit, defaulting to 100ms. When a single lua state has been executing for longer than this limit, it will eventually stop and produce an error.
To avoid exceeding the execution limit, call `sleep()` or `coroutine.yield()` before the execution limit is reached.
### over_exec_usage(fraction = 0.95)
This function returns whether the current run of the Lua VM has executed for longer than the specified fraction of the execution limit. You can use this function to branch to a call to `sleep()` or `coroutine.yield()` to maximize the amount of work done in a single run of the Lua VM. If nil, `fraction` will default to 0.95, otherwise, it will be clamped to the range \[0, 1\].
---
## Task management
The Lua Scripting subsystem manages the execution of tasks for each Lua state. A single fire of the subsystem behaves as follows:
- All tasks that slept since the last fire are resumed in the order they slept.
- For each queued resume, the corresponding task is resumed.
### sleep()
Yields the current thread, scheduling it to be resumed during the next fire of SSlua. Use this function to prevent your Lua code from exceeding its allowed execution duration. Under the hood, `sleep` performs the following:
- Sets the [`sleep_flag`](#sleep_flag)
- Calls `coroutine.yield()`
- Clears the sleep flag when determining whether the task slept or yielded
- Ignores the return values of `coroutine.yield()` once resumed
---
## The SS13 package
The `SS13` package contains various helper functions that use code specific to tgstation.
### SS13.state
A reference to the state datum (`/datum/lua_state`) handling this Lua state.
### SS13.get_runner_ckey()
The ckey of the user who ran the lua script in the current context. Can be unreliable if accessed after sleeping.
### SS13.get_runner_client()
Returns the client of the user who ran the lua script in the current context. Can be unreliable if accessed after sleeping.
### SS13.global_proc
=======
# Objects
Datums, lists, typepaths, static appearances, and some other objects are represented in Luau as userdata. Certain operations can be performed on these types of objects.
@@ -369,7 +220,6 @@ The ckey of the user who ran the lua script in the current context. Can be unrel
Returns the client of the user who ran the lua script in the current context. Can be unreliable if accessed after sleeping.
## SS13.global_proc
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
A wrapper for the magic string used to tell `WrapAdminProcCall` to call a global proc.
For instance, `/datum/callback` must be instantiated with `SS13.global_proc` as its first argument to specify that it will be invoking a global proc.
The following example declares a callback which will execute the global proc `to_chat`:
@@ -377,22 +227,6 @@ The following example declares a callback which will execute the global proc `to
local callback = SS13.new("/datum/callback", SS13.global_proc, "to_chat", dm.world, "Hello World")
```
<<<<<<< HEAD
### SS13.istype(thing, type)
Equivalent to the DM statement `istype(thing, text2path(type))`.
### SS13.new(type, ...)
Instantiates a datum of type `type` with `...` as the arguments passed to `/proc/_new`
The following example spawns a singularity at the caller's current turf:
```lua
SS13.new("/obj/singularity", dm.global_proc("_get_step", dm.usr, 0))
```
### SS13.new_untracked(type, ...)
Works exactly like SS13.new but it does not store the value to the lua state's `references` list variable. This means that the variable could end up deleted if nothing holds a reference to it.
### SS13.is_valid(datum)
=======
## SS13.istype(thing, type)
Equivalent to the DM statement `istype(thing, text2path(type))`.
@@ -400,16 +234,11 @@ Equivalent to the DM statement `istype(thing, text2path(type))`.
An alias for `dm.new`
## SS13.is_valid(datum)
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
Can be used to determine if the datum passed is not nil, not undefined and not qdel'd all in one. A helper function that allows you to check the validity from only one function.
Example usage:
```lua
local datum = SS13.new("/datum")
<<<<<<< HEAD
dm.global_proc("qdel", datum)
=======
dm.global_procs.qdel(datum)
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
print(SS13.is_valid(datum)) -- false
local null = nil
@@ -419,15 +248,6 @@ local datum = SS13.new("/datum")
print(SS13.is_valid(datum)) -- true
```
<<<<<<< HEAD
### SS13.type(string)
Converts a string into a type. Equivalent to doing `dm.global_proc("_text2path", "/path/to/type")`
### SS13.qdel(datum)
Deletes a datum. You shouldn't try to reference it after calling this function. Equivalent to doing `dm.global_proc("qdel", datum)`
### SS13.await(thing_to_call, proc_to_call, ...)
=======
## SS13.type(string)
Converts a string into a typepath. Equivalent to doing `dm.global_proc("_text2path", "/path/to/type")`
@@ -435,7 +255,6 @@ Converts a string into a typepath. Equivalent to doing `dm.global_proc("_text2pa
Deletes a datum. You shouldn't try to reference it after calling this function. Equivalent to doing `dm.global_proc("qdel", datum)`
## SS13.await(thing_to_call, proc_to_call, ...)
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
Calls `proc_to_call` on `thing_to_call`, with `...` as its arguments, and sleeps until that proc returns.
Returns two return values - the first is the return value of the proc, and the second is the message of any runtime exception thrown by the called proc.
The following example calls and awaits the return of `poll_ghost_candidates`:
@@ -443,104 +262,59 @@ The following example calls and awaits the return of `poll_ghost_candidates`:
local ghosts, runtime = SS13.await(SS13.global_proc, "poll_ghost_candidates", "Would you like to be considered for something?")
```
<<<<<<< HEAD
### SS13.wait(time, timer)
=======
## SS13.wait(time, timer)
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
Waits for a number of **seconds** specified with the `time` argument. You can optionally specify a timer subsystem using the `timer` argument.
Internally, this function creates a timer that will resume the current task after `time` seconds, then yields the current task by calling `coroutine.yield` with no arguments and ignores the return values. If the task is prematurely resumed, the timer will be safely deleted.
<<<<<<< HEAD
### SS13.register_signal(datum, signal, func, make_easy_clear_function)
=======
## SS13.register_signal(datum, signal, func)
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
Registers the Lua function `func` as a handler for `signal` on `datum`.
Like with signal handlers written in DM, Lua signal handlers should not sleep (either by calling `sleep` or `coroutine.yield`).
<<<<<<< HEAD
If `make_easy_clear_function` is truthy, a member function taking no arguments will be created in the `SS13` table to easily unregister the signal handler.
This function returns the `/datum/callback` created to call `func` from DM.
=======
This function returns whether the signal registration was successful.
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
The following example defines a function which will register a signal that makes `target` make a honking sound any time it moves:
```lua
function honk(target)
SS13.register_signal(target, "movable_moved", function(source)
<<<<<<< HEAD
dm.global_proc("playsound", target, "sound/items/bikehorn.ogg", 100, true)
=======
dm.global_procs.playsound(target, "sound/items/bikehorn.ogg", 100, true)
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
end)
end
```
<<<<<<< HEAD
### SS13.unregister_signal(datum, signal, callback)
Unregister a signal previously registered using `SS13.register_signal`. `callback` should be a `datum/callback` previously returned by `SS13.register_signal`. If `callback` is not specified, **ALL** signal handlers registered on `datum` for `signal` will be unregistered.
### SS13.set_timeout(time, func)
=======
NOTE: if `func` is an anonymous function declared inside the call to `SS13.register_signal`, it cannot be referenced in order to unregister that signal with `SS13.unregister_signal`
## SS13.unregister_signal(datum, signal, func)
Unregister a signal previously registered using `SS13.register_signal`. `func` must be a function for which a handler for the specified signal has already been registered. If `func` is `nil`, all handlers for that signal will be unregistered.
## SS13.set_timeout(time, func)
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
Creates a timer which will execute `func` after `time` **seconds**. `func` should not expect to be passed any arguments, as it will not be passed any. Unlike `SS13.wait`, `SS13.set_timeout` does not yield or sleep the current task, making it suitable for use in signal handlers for `SS13.register_signal`
The following example will output a message to chat after 5 seconds:
```lua
SS13.set_timeout(5, function()
<<<<<<< HEAD
dm.global_proc("to_chat", dm.world, "Hello World!")
end)
```
### SS13.start_loop(time, amount, func)
=======
dm.global_procs.to_chat(dm.world, "Hello World!")
end)
```
## SS13.start_loop(time, amount, func)
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
Creates a timer which will execute `func` after `time` **seconds**. `func` should not expect to be passed any arguments, as it will not be passed any. Works exactly the same as `SS13.set_timeout` except it will loop the timer `amount` times. If `amount` is set to -1, it will loop indefinitely. Returns a number value, which represents the timer's id. Can be stopped with `SS13.end_loop`
Returns a number, the timer id, which is needed to stop indefinite timers.
The following example will output a message to chat every 5 seconds, repeating 10 times:
```lua
SS13.start_loop(5, 10, function()
<<<<<<< HEAD
dm.global_proc("to_chat", dm.world, "Hello World!")
=======
dm.global_procs.to_chat(dm.world, "Hello World!")
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
end)
```
The following example will output a message to chat every 5 seconds, until `SS13.end_loop(timerid)` is called:
```lua
local timerid = SS13.start_loop(5, -1, function()
<<<<<<< HEAD
dm.global_proc("to_chat", dm.world, "Hello World!")
end)
```
### SS13.end_loop(id)
=======
dm.global_proc.to_chat(dm.world, "Hello World!")
end)
```
## SS13.end_loop(id)
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
Prematurely ends a loop that hasn't ended yet, created with `SS13.start_loop`. Silently fails if there is no started loop with the specified id.
The following example will output a message to chat every 5 seconds and delete it after it has repeated 20 times:
```lua
@@ -548,11 +322,7 @@ local repeated_amount = 0
-- timerid won't be in the looping function's scope if declared before the function is declared.
local timerid
timerid = SS13.start_loop(5, -1, function()
<<<<<<< HEAD
dm.global_proc("to_chat", dm.world, "Hello World!")
=======
dm.global_procs.to_chat(dm.world, "Hello World!")
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
repeated_amount += 1
if repeated_amount >= 20 then
SS13.end_loop(timerid)
@@ -560,41 +330,6 @@ timerid = SS13.start_loop(5, -1, function()
end)
```
<<<<<<< HEAD
### SS13.stop_all_loops()
Stops all current running loops that haven't ended yet.
Useful in case you accidentally left a indefinite loop running without storing the id anywhere.
### SS13.stop_tracking(datum)
Stops tracking a datum that was created via `SS13.new` so that it can be garbage collected and deleted without having to qdel. Should be used for things like callbacks and other such datums where the reference to the variable is no longer needed.
---
## Internal globals
Auxlua defines several registry values for each state. Note that there is no way to access registry values from lua code.
### sleep_flag
This flag is used to designate that a yielding task should be put in the sleep queue instead of the yield table. Once auxlua determines that a task should sleep, `sleep_flag` is cleared.
### sleep_queue
A sequence of threads, each corresponding to a task that has slept. When calling `/proc/__lua_awaken`, auxlua will dequeue the first thread from the sequence and resume it.
### yield_table
A table of threads, each corresponding to a coroutine that has yielded. When calling `/proc/__lua_resume`, auxlua will look for a thread at the index specified in the `index` argument, and resume it with the arguments specified in the `arguments` argument.
### task_info
A table of key-value-pairs, where the keys are threads, and the values are tables consisting of the following fields:
- name: A string containing the name of the task
- status: A string, either "sleep" or "yield"
- index: The task's index in `sleep_queue` or `yield_table`
=======
## SS13.stop_all_loops()
Stops all current running loops that haven't ended yet.
Useful in case you accidentally left a indefinite loop running without storing the id anywhere.
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
-17
View File
@@ -1,5 +1,3 @@
<<<<<<< HEAD
=======
/proc/wrap_lua_get_var(datum/thing, var_name)
SHOULD_NOT_SLEEP(TRUE)
if(thing == world)
@@ -9,7 +7,6 @@
if(thing.can_vv_get(var_name))
return thing.vars[var_name]
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
/proc/wrap_lua_set_var(datum/thing_to_set, var_name, value)
SHOULD_NOT_SLEEP(TRUE)
thing_to_set.vv_edit_var(var_name, value)
@@ -23,11 +20,6 @@
ret = WrapAdminProcCall(thing_to_call, proc_name, arguments)
else
ret = HandleUserlessProcCall("lua", thing_to_call, proc_name, arguments)
<<<<<<< HEAD
if(isdatum(ret))
SSlua.gc_guard += ret
=======
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
return ret
/proc/wrap_lua_global_proc_call(proc_name, list/arguments)
@@ -39,11 +31,6 @@
ret = WrapAdminProcCall(GLOBAL_PROC, proc_name, arguments)
else
ret = HandleUserlessProcCall("lua", GLOBAL_PROC, proc_name, arguments)
<<<<<<< HEAD
if(isdatum(ret))
SSlua.gc_guard += ret
=======
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
return ret
/proc/wrap_lua_print(state_id, list/arguments)
@@ -56,10 +43,6 @@
if(!target_state)
return
var/print_message = jointext(arguments, "\t")
<<<<<<< HEAD
var/result = list("status" = "print", "param" = print_message)
=======
var/result = list("status" = "print", "message" = print_message)
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
INVOKE_ASYNC(target_state, TYPE_PROC_REF(/datum/lua_state, log_result), result, TRUE)
log_lua("[target_state]: [print_message]")
-19
View File
@@ -3,38 +3,20 @@
#define PROMISE_REJECTED 2
/**
<<<<<<< HEAD
* Auxtools hooks act as "set waitfor = 0" procs. This means that whenever
* a proc directly called from auxtools sleeps, the hook returns with whatever
=======
* Byondapi hooks act as "set waitfor = 0" procs. This means that whenever
* a proc directly called from an external library sleeps, the hook returns with whatever
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
* the called proc had as its return value at the moment it slept. This may not
* be desired behavior, so this datum exists to wrap these procs.
*
* Some procs that don't sleep could take longer than the execution limit would
* allow for. We can wrap these in a promise as well.
*/
<<<<<<< HEAD
/datum/auxtools_promise
=======
/datum/promise
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
var/datum/callback/callback
var/return_value
var/runtime_message
var/status = PROMISE_PENDING
<<<<<<< HEAD
/datum/auxtools_promise/New(...)
callback = CALLBACK(arglist(args))
perform()
/datum/auxtools_promise/proc/perform()
set waitfor = 0
sleep() //In case we have to call a super-expensive non-sleeping proc (like getFlatIcon)
=======
/datum/promise/New(...)
if(!usr)
usr = GLOB.lua_usr
@@ -42,7 +24,6 @@
INVOKE_ASYNC(src, PROC_REF(perform))
/datum/promise/proc/perform()
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
try
return_value = callback.Invoke()
status = PROMISE_RESOLVED
-105
View File
@@ -16,15 +16,12 @@
/// If set, we will force the editor to look at this chunk
var/force_view_chunk
<<<<<<< HEAD
=======
/// If set, we will force the script input to be this
var/force_input
/// If set, the latest code execution performed from the editor raised an error, and this is the message from that error
var/last_error
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
/datum/lua_editor/New(state, _quick_log_index)
. = ..()
if(state)
@@ -46,32 +43,16 @@
/datum/lua_editor/ui_state(mob/user)
return GLOB.debug_state
<<<<<<< HEAD
/datum/lua_editor/ui_static_data(mob/user)
var/list/data = list()
data["documentation"] = file2text('code/modules/admin/verbs/lua/README.md')
data["auxtools_enabled"] = CONFIG_GET(flag/auxtools_enabled)
data["ss_lua_init"] = SSlua.initialized
return data
/datum/lua_editor/ui_data(mob/user)
var/list/data = list()
if(!CONFIG_GET(flag/auxtools_enabled) || !SSlua.initialized)
=======
/datum/lua_editor/ui_data(mob/user)
var/list/data = list()
data["ss_lua_init"] = SSlua.initialized
if(!SSlua.initialized)
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
return data
data["noStateYet"] = !current_state
data["showGlobalTable"] = show_global_table
if(current_state)
if(current_state.log)
<<<<<<< HEAD
data["stateLog"] = kvpify_list(refify_list(current_state.log.Copy((page*50)+1, min((page+1)*50+1, current_state.log.len+1))))
=======
var/list/logs = current_state.log.Copy((page*50)+1, min((page+1)*50+1, current_state.log.len+1))
for(var/i in 1 to logs.len)
var/list/log = logs[i]
@@ -80,17 +61,11 @@
log["return_values"] = kvpify_list(prepare_lua_editor_list(deep_copy_without_cycles(log["return_values"])))
logs[i] = log
data["stateLog"] = logs
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
data["page"] = page
data["pageCount"] = CEILING(current_state.log.len/50, 1)
data["tasks"] = current_state.get_tasks()
if(show_global_table)
current_state.get_globals()
<<<<<<< HEAD
data["globals"] = kvpify_list(refify_list(current_state.globals))
data["states"] = SSlua.states
data["callArguments"] = kvpify_list(refify_list(arguments))
=======
var/list/values = current_state.globals["values"]
values = deep_copy_without_cycles(values)
values = prepare_lua_editor_list(values)
@@ -105,19 +80,15 @@
for(var/datum/lua_state/state as anything in SSlua.states)
data["states"] += state.display_name
data["callArguments"] = kvpify_list(prepare_lua_editor_list(deep_copy_without_cycles(arguments)))
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
if(force_modal)
data["forceModal"] = force_modal
force_modal = null
if(force_view_chunk)
data["forceViewChunk"] = force_view_chunk
force_view_chunk = null
<<<<<<< HEAD
=======
if(force_input)
data["force_input"] = force_input
force_input = null
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
return data
/datum/lua_editor/proc/traverse_list(list/path, list/root, traversal_depth_offset = 0)
@@ -149,16 +120,6 @@
else
return root
<<<<<<< HEAD
/datum/lua_editor/ui_act(action, list/params)
. = ..()
if(.)
return
if(!check_rights_for(usr.client, R_DEBUG))
return
if(action == "runCodeFile")
params["code"] = file2text(input(usr, "Input File") as null|file)
=======
/datum/lua_editor/proc/run_code(code)
var/ckey = usr.ckey
current_state.ckey_last_runner = ckey
@@ -177,7 +138,6 @@
return
if(action == "runCodeFile")
params["code"] = file2text(input(user, "Input File") as null|file)
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
if(isnull(params["code"]))
return
action = "runCode"
@@ -187,11 +147,8 @@
if(!length(state_name))
return TRUE
var/datum/lua_state/new_state = new(state_name)
<<<<<<< HEAD
=======
if(QDELETED(new_state))
return
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
SSlua.states += new_state
LAZYREMOVEASSOC(SSlua.editors, text_ref(current_state), src)
current_state = new_state
@@ -206,13 +163,6 @@
page = 0
return TRUE
if("runCode")
<<<<<<< HEAD
var/code = params["code"]
current_state.ckey_last_runner = usr.ckey
var/result = current_state.load_script(code)
var/index_with_result = current_state.log_result(result)
message_admins("[key_name(usr)] executed [length(code)] bytes of lua code. [ADMIN_LUAVIEW_CHUNK(current_state, index_with_result)]")
=======
run_code(params["code"])
return TRUE
if("runFile")
@@ -221,7 +171,6 @@
return TRUE
var/code = file2text(code_file)
run_code(code)
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
return TRUE
if("moveArgUp")
var/list/path = params["path"]
@@ -245,15 +194,9 @@
var/list/path = params["path"]
var/list/target_list = traverse_list(path, arguments)
if(target_list != arguments)
<<<<<<< HEAD
usr?.client?.mod_list_add(target_list, null, "a lua editor", "arguments")
else
var/list/vv_val = usr?.client?.vv_get_value(restricted_classes = list(VV_RESTORE_DEFAULT))
=======
user?.client?.mod_list_add(target_list, null, "a lua editor", "arguments")
else
var/list/vv_val = user?.client?.vv_get_value(restricted_classes = list(VV_RESTORE_DEFAULT))
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
var/class = vv_val["class"]
if(!class)
return
@@ -261,43 +204,22 @@
return TRUE
if("callFunction")
var/list/recursive_indices = params["indices"]
<<<<<<< HEAD
var/list/current_list = kvpify_list(current_state.globals)
=======
var/list/current_list = kvpify_list(current_state.globals["values"])
var/list/current_variants = current_state.globals["variants"]
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
var/function = list()
while(LAZYLEN(recursive_indices))
var/index = popleft(recursive_indices)
var/list/element = current_list[index]
var/key = element["key"]
var/value = element["value"]
<<<<<<< HEAD
if(!(istext(key) || isnum(key)))
to_chat(usr, span_warning("invalid key \[[key]] for function call (expected text or num)"))
=======
var/list/variant_pair = current_variants[index]
var/key_variant = variant_pair["key"]
if(key_variant == "function" || key_variant == "thread" || key_variant == "userdata" || key_variant == "error_as_value")
to_chat(user, span_warning("invalid table key \[[key]] for function call (expected text, num, path, list, or ref, got [key_variant])"))
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
return
function += key
if(islist(value))
current_list = value
<<<<<<< HEAD
else
var/regex/function_regex = regex("^function: 0x\[0-9a-fA-F]+$")
if(function_regex.Find(value))
break
to_chat(usr, span_warning("invalid path element \[[value]] for function call (expected list or text matching [function_regex])"))
return
var/result = current_state.call_function(arglist(list(function) + arguments))
current_state.log_result(result)
arguments.Cut()
return TRUE
=======
current_variants = variant_pair["value"]
else
if(variant_pair["value"] != "function")
@@ -309,39 +231,19 @@
last_error = result["message"]
arguments.Cut()
return
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
if("resumeTask")
var/task_index = params["index"]
SSlua.queue_resume(current_state, task_index, arguments)
arguments.Cut()
return TRUE
if("killTask")
<<<<<<< HEAD
var/task_info = params["info"]
SSlua.kill_task(current_state, task_info)
=======
var/is_sleep = params["is_sleep"]
var/index = params["index"]
SSlua.kill_task(current_state, is_sleep, index)
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
return TRUE
if("vvReturnValue")
var/log_entry_index = params["entryIndex"]
var/list/log_entry = current_state.log[log_entry_index]
<<<<<<< HEAD
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, TYPE_PROC_REF(/client, 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, TYPE_PROC_REF(/client, debug_variables), thing_to_debug)
=======
var/thing_to_debug = traverse_list(params["indices"], log_entry["return_values"])
if(isweakref(thing_to_debug))
var/datum/weakref/ref = thing_to_debug
@@ -354,7 +256,6 @@
var/datum/weakref/ref = thing_to_debug
thing_to_debug = ref.resolve()
INVOKE_ASYNC(user.client, TYPE_PROC_REF(/client, debug_variables), thing_to_debug)
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
return FALSE
if("clearArgs")
arguments.Cut()
@@ -362,24 +263,18 @@
if("toggleShowGlobalTable")
show_global_table = !show_global_table
return TRUE
<<<<<<< HEAD
=======
if("toggleSupressRuntimes")
current_state.supress_runtimes = !current_state.supress_runtimes
return TRUE
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
if("nextPage")
page = min(page+1, CEILING(current_state.log.len/50, 1)-1)
return TRUE
if("previousPage")
page = max(page-1, 0)
return TRUE
<<<<<<< HEAD
=======
if("nukeLog")
current_state.log.Cut()
return TRUE
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
/datum/lua_editor/ui_close(mob/user)
. = ..()
-142
View File
@@ -1,17 +1,5 @@
#define MAX_LOG_REPEAT_LOOKBACK 5
<<<<<<< HEAD
GLOBAL_VAR_INIT(IsLuaCall, FALSE)
GLOBAL_PROTECT(IsLuaCall)
GLOBAL_DATUM(lua_usr, /mob)
GLOBAL_PROTECT(lua_usr)
/datum/lua_state
var/name
/// The internal ID of the lua state stored in auxlua's global map
=======
GLOBAL_DATUM(lua_usr, /mob)
GLOBAL_PROTECT(lua_usr)
@@ -22,7 +10,6 @@ GLOBAL_PROTECT(lua_state_stack)
var/display_name
/// The internal ID of the lua state stored in dreamluau's state list
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
var/internal_id
/// A log of every return, yield, and error for each chunk execution and function call
@@ -31,24 +18,15 @@ GLOBAL_PROTECT(lua_state_stack)
/// A list of all the variables in the state's environment
var/list/globals = list()
<<<<<<< HEAD
/// A list in which to store datums and lists instantiated in lua, ensuring that they don't get garbage collected
var/list/references = list()
=======
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
/// Ckey of the last user who ran a script on this lua state.
var/ckey_last_runner = ""
/// Whether the timer.lua script has been included into this lua context state.
var/timer_enabled = FALSE
<<<<<<< HEAD
=======
/// Whether to supress logging BYOND runtimes for this state.
var/supress_runtimes = FALSE
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
/// Callbacks that need to be ran on next tick
var/list/functions_to_execute = list()
@@ -61,13 +39,6 @@ GLOBAL_PROTECT(lua_state_stack)
if(SSlua.initialized != TRUE)
qdel(src)
return
<<<<<<< HEAD
name = _name
internal_id = __lua_new_state()
/datum/lua_state/proc/check_if_slept(result)
if(result["status"] == "sleeping")
=======
display_name = _name
internal_id = DREAMLUAU_NEW_STATE()
if(isnull(internal_id))
@@ -79,42 +50,21 @@ GLOBAL_PROTECT(lua_state_stack)
/datum/lua_state/proc/check_if_slept(result)
if(result["status"] == "sleep")
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
SSlua.sleeps += src
/datum/lua_state/proc/log_result(result, verbose = TRUE)
if(!islist(result))
return
<<<<<<< HEAD
if(!verbose && result["status"] != "errored" && result["status"] != "bad return" \
&& !(result["name"] == "input" && (result["status"] == "finished" || length(result["param"]))))
=======
var/status = result["status"]
if(!verbose && status != "error" && status != "panic" && status != "runtime" && !(result["name"] == "input" && (status == "finished" || length(result["return_values"]))))
return
if(status == "runtime" && supress_runtimes)
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
return
var/append_to_log = TRUE
var/index_of_log
if(log.len)
for(var/index in log.len to max(log.len - MAX_LOG_REPEAT_LOOKBACK, 1) step -1)
var/list/entry = log[index]
<<<<<<< HEAD
if(entry["status"] == result["status"] \
&& entry["chunk"] == result["chunk"] \
&& entry["name"] == result["name"] \
&& ((entry["param"] == result["param"]) || deep_compare_list(entry["param"], result["param"])))
if(!entry["repeats"])
entry["repeats"] = 0
index_of_log = index
entry["repeats"]++
append_to_log = FALSE
break
if(append_to_log)
if(islist(result["param"]))
result["param"] = weakrefify_list(encode_text_and_nulls(result["param"]))
=======
if(!compare_lua_logs(entry, result))
continue
if(!entry["repeats"])
@@ -127,20 +77,11 @@ GLOBAL_PROTECT(lua_state_stack)
if(islist(result["return_values"]))
add_lua_return_value_variants(result["return_values"], result["variants"])
result["return_values"] = weakrefify_list(result["return_values"])
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
log += list(result)
index_of_log = log.len
INVOKE_ASYNC(src, TYPE_PROC_REF(/datum/lua_state, update_editors))
return index_of_log
<<<<<<< HEAD
/datum/lua_state/proc/load_script(script)
GLOB.IsLuaCall = TRUE
var/tmp_usr = GLOB.lua_usr
GLOB.lua_usr = usr
var/result = __lua_load(internal_id, script)
GLOB.IsLuaCall = FALSE
=======
/datum/lua_state/proc/parse_error(message, name)
if(copytext(message, 1, 7) == "PANIC:")
return list("status" = "panic", "message" = copytext(message, 7), "name" = name)
@@ -155,20 +96,13 @@ GLOBAL_PROTECT(lua_state_stack)
var/result = DREAMLUAU_LOAD(internal_id, script, "input")
SSlua.needs_gc_cycle |= src
pop(GLOB.lua_state_stack)
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
GLOB.lua_usr = tmp_usr
// Internal errors unrelated to the code being executed are returned as text rather than lists
if(isnull(result))
<<<<<<< HEAD
result = list("status" = "errored", "param" = "__lua_load returned null (it may have runtimed - check the runtime logs)", "name" = "input")
if(istext(result))
result = list("status" = "errored", "param" = result, "name" = "input")
=======
result = list("status" = "error", "message" = "load returned null (it may have runtimed - check the runtime logs)", "name" = "input")
if(istext(result))
result = parse_error(result, "input")
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
result["chunk"] = script
check_if_slept(result)
@@ -190,22 +124,6 @@ GLOBAL_PROTECT(lua_state_stack)
if(islist(function))
var/list/new_function_path = list()
for(var/path_element in function)
<<<<<<< HEAD
new_function_path += path_element
function = new_function_path
var/tmp_usr = GLOB.lua_usr
GLOB.lua_usr = usr
GLOB.IsLuaCall = TRUE
var/result = __lua_call(internal_id, function, call_args)
GLOB.IsLuaCall = FALSE
GLOB.lua_usr = tmp_usr
if(isnull(result))
result = list("status" = "errored", "param" = "__lua_call returned null (it may have runtimed - check the runtime logs)", "name" = islist(function) ? jointext(function, ".") : function)
if(istext(result))
result = list("status" = "errored", "param" = result, "name" = islist(function) ? jointext(function, ".") : function)
=======
if(isweakref(path_element))
var/datum/weakref/weak_ref = path_element
var/resolved = weak_ref.hard_resolve()
@@ -231,28 +149,10 @@ GLOBAL_PROTECT(lua_state_stack)
result = list("status" = "error", "message" = "call_function returned null (it may have runtimed - check the runtime logs)", "name" = jointext(function, "."))
if(istext(result))
result = parse_error(result, jointext(function, "."))
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
check_if_slept(result)
return result
/datum/lua_state/proc/call_function_return_first(function, ...)
<<<<<<< HEAD
var/list/result = call_function(arglist(args))
log_result(result, verbose = FALSE)
if(length(result))
if(islist(result["param"]) && length(result["param"]))
return result["param"][1]
/datum/lua_state/proc/awaken()
GLOB.IsLuaCall = TRUE
var/result = __lua_awaken(internal_id)
GLOB.IsLuaCall = FALSE
if(isnull(result))
result = list("status" = "errored", "param" = "__lua_awaken returned null (it may have runtimed - check the runtime logs)", "name" = "An attempted awaken")
if(istext(result))
result = list("status" = "errored", "param" = result, "name" = "An attempted awaken")
=======
SHOULD_NOT_SLEEP(TRUE) // This function is meant to be used for signal handlers.
var/list/result = call_function(arglist(args))
INVOKE_ASYNC(src, PROC_REF(log_result), deep_copy_list(result), /*verbose = */FALSE)
@@ -275,26 +175,12 @@ GLOBAL_PROTECT(lua_state_stack)
result = list("status" = "error", "message" = "awaken returned null (it may have runtimed - check the runtime logs)", "name" = "An attempted awaken")
if(istext(result))
result = parse_error(result, "An attempted awaken")
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
check_if_slept(result)
return result
/// Prefer calling SSlua.queue_resume over directly calling this
/datum/lua_state/proc/resume(index, ...)
var/call_args = length(args) > 1 ? args.Copy(2) : list()
<<<<<<< HEAD
var/msg = "[key_name(usr)] resumed a lua coroutine with arguments: [english_list(call_args)]"
log_lua(msg)
GLOB.IsLuaCall = TRUE
var/result = __lua_resume(internal_id, index, call_args)
GLOB.IsLuaCall = FALSE
if(isnull(result))
result = list("status" = "errored", "param" = "__lua_resume returned null (it may have runtimed - check the runtime logs)", "name" = "An attempted resume")
if(istext(result))
result = list("status" = "errored", "param" = result, "name" = "An attempted resume")
=======
DREAMLUAU_SET_USR
GLOB.lua_state_stack += WEAKREF(src)
@@ -306,20 +192,10 @@ GLOBAL_PROTECT(lua_state_stack)
result = list("status" = "error", "param" = "resume returned null (it may have runtimed - check the runtime logs)", "name" = "An attempted resume")
if(istext(result))
result = parse_error(result, "An attempted resumt")
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
check_if_slept(result)
return result
/datum/lua_state/proc/get_globals()
<<<<<<< HEAD
globals = weakrefify_list(encode_text_and_nulls(__lua_get_globals(internal_id)))
/datum/lua_state/proc/get_tasks()
return __lua_get_tasks(internal_id)
/datum/lua_state/proc/kill_task(task_info)
__lua_kill_task(internal_id, task_info)
=======
var/result = DREAMLUAU_GET_GLOBALS(internal_id)
if(isnull(result))
CRASH("get_globals returned null")
@@ -348,7 +224,6 @@ GLOBAL_PROTECT(lua_state_stack)
var/result = DREAMLUAU_COLLECT_GARBAGE(internal_id)
if(!isnull(result))
CRASH(result)
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
/datum/lua_state/proc/update_editors()
var/list/editor_list = LAZYACCESS(SSlua.editors, text_ref(src))
@@ -356,21 +231,4 @@ GLOBAL_PROTECT(lua_state_stack)
for(var/datum/lua_editor/editor as anything in editor_list)
SStgui.update_uis(editor)
<<<<<<< HEAD
/// Called by lua scripts when they add an atom to var/list/references so that it gets cleared up on delete.
/datum/lua_state/proc/clear_on_delete(datum/to_clear)
RegisterSignal(to_clear, COMSIG_QDELETING, PROC_REF(on_delete))
/// Called by lua scripts when an atom they've added should soft delete and this state should stop tracking it.
/// Needs to unregister all signals.
/datum/lua_state/proc/let_soft_delete(datum/to_clear)
UnregisterSignal(to_clear, COMSIG_QDELETING, PROC_REF(on_delete))
references -= to_clear
/datum/lua_state/proc/on_delete(datum/to_clear)
SIGNAL_HANDLER
references -= to_clear
=======
>>>>>>> 4b4ae0958fe6b5d511ee6e24a5087599f61d70a3
#undef MAX_LOG_REPEAT_LOOKBACK