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. Common metamethodsThe following metamethods are defined for all objects. __tostring(): stringReturns the string representation of the object. This uses BYOND's internal string conversion function. __eq(other: any): booleanCompare the equality of two objects. While passing the same object into luau twice will return two references to the same userdata, some DM projects may override the equality operator using an Datum-like ObjectsDatum-like objects include datums themselves, clients (if they have not been redefined to be children of __index(index: string): anyAccess the member specified by If For objects other than static appearances, if __newindex(index: string, value: any): ()Set the var specified by If the var setting wrapper proc is set, the operation will instead call that proc with the arguments ListsLists are syntactically similar to tables, with one crucial difference. Unlike tables, numeric indices must be non-zero integers within the bounds of the list. __index(index: any): anyRead the list at __newindex(index: any, value: any): anyWrite __len(): integerReturns the length of the list, similarly to the IterationLists support Luau's generalized iteration. Iteration this way returns pairs of numeric indices and list values.
For example, the statement Global Fields and ModulesIn addition to the full extent of Luau's standard library modules, some extra functions and modules have been added. Global-Level Fieldssleep(): ()Yields the active thread, without worrying about passing data into or out of the state. Threads yielded this way are placed at the end of a queue. Call the loadstring(code: string): functionLuau does not inherently include the print(...any): ()Calls the print wrapper with the passed in arguments. Raises an error if no print wrapper is set, as that means there is nothing to print with. _state_id: integerThe handle to the underlying luau state in the dreamluau binary. _execThe _next_yield_index: integerWhen yielding a thread with _limit: integer?If set, the execution limit, rounded to the nearest millisecond. _time: integerThe length of successive time luau code has been executed, including recursive calls to DM and back into luau, rounded to the nearest millisecond. dmThe world: userdataA static reference to the DM global_vars: userdataA static reference that functions like the DM keyword global_procs: tableA table that can be indexed by string for functions that wrap global procs. Due to BYOND limitations, attempting to index an invalid proc returns a function logically equivalent to a no-op. get_var(object: userdata, var: string): functionReads the var new(path: string, ...any): userdataCreates an instance of the object specified by is_valid_ref(ref: any): booleanReturns true if the value passed in corresponds to a valid reference-counted DM object. usr: userdata?Corresponds to the DM var listThe add(list: userdata, ...any): ()Logically equivalent to the DM statement copy(list: userdata, start?: integer, end?: integer): userdataLogically equivalent to the DM statement cut(list: userdata, start?: integer, end?: integer): userdataLogically equivalent to the DM statement find(list: userdata, item: any, start?: integer, end?: integer): integerLogically equivalent to the DM statement insert(list: userdata, index: integer, ...any): integerLogically equivalent to the DM statement join(list: userdata, glue: string, start?: integer, end?: integer): stringLogically equivalent to the statement remove(list: userdata, ...any): integerLogically equivalent to the DM statement remove_all(list: userdata, ...any): integerLogically equivalent to the DM statement splice(list: userdata, start?: integer, end?: integer, ...any): ()Logically equivalent to the DM statement swap(list: userdata, index_1: integer, index_2: integer): ()Logically equivalent to the DM statement to_table(list: userdata, deep?: boolean): tableCreates a table that is a copy of from_table(table: table): userdataCreates a list that is a copy of filter(list: userdata, path: string): userdataReturns a copy of pointerThe read(pointer: userdata): anyGets the underlying data the pointer references. write(pointer: userdata, value: any): ()Writes unwrap(possible_pointer: any): anyIf The SS13 packageThe SS13.stateA reference to the state datum ( 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_procA wrapper for the magic string used to tell
SS13.istype(thing, type)Equivalent to the DM statement SS13.new(type, ...)An alias for SS13.is_valid(datum)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:
SS13.type(string)Converts a string into a typepath. Equivalent to doing SS13.qdel(datum)Deletes a datum. You shouldn't try to reference it after calling this function. Equivalent to doing SS13.await(thing_to_call, proc_to_call, ...)Calls
SS13.wait(time, timer)Waits for a number of seconds specified with the Internally, this function creates a timer that will resume the current task after SS13.register_signal(datum, signal, func)Registers the Lua function Like with signal handlers written in DM, Lua signal handlers should not sleep (either by calling This function returns whether the signal registration was successful. The following example defines a function which will register a signal that makes
NOTE: if SS13.unregister_signal(datum, signal, func)Unregister a signal previously registered using SS13.set_timeout(time, func)Creates a timer which will execute The following example will output a message to chat after 5 seconds:
SS13.start_loop(time, amount, func)Creates a timer which will execute
The following example will output a message to chat every 5 seconds, until
SS13.end_loop(id)Prematurely ends a loop that hasn't ended yet, created with
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. |