mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-01-14 02:43:16 +00:00
## About The Pull Request Ever since byondapi went stable, I've been meaning to create a replacement lua library that uses it instead of the auxtools-based auxlua. After so many months, I've finally got the code just about into a position where it's ready for a PR. [Click here](https://hackmd.io/@aloZJicNQrmfYgykhfFwAQ/BySAS18u0) for a guide to rewriting auxlua scripts for dreamluau syntax. ## Why It's Good For The Game Code that runs on production servers should not depend on memory hacks that are liable to break any time Dream Daemon updates. ## Changelog 🆑 admin: Admin lua scripting uses a new library that (probably) will not break when BYOND updates. /🆑 ## TODO: - [x] Convert the lua editor ui to TS - [x] Include a guide for converting scripts from auxlua syntax to dreamluau syntax
37 lines
1.0 KiB
Plaintext
37 lines
1.0 KiB
Plaintext
#define PROMISE_PENDING 0
|
|
#define PROMISE_RESOLVED 1
|
|
#define PROMISE_REJECTED 2
|
|
|
|
/**
|
|
* 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
|
|
* 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.
|
|
*/
|
|
/datum/promise
|
|
var/datum/callback/callback
|
|
var/return_value
|
|
var/runtime_message
|
|
var/status = PROMISE_PENDING
|
|
|
|
/datum/promise/New(...)
|
|
if(!usr)
|
|
usr = GLOB.lua_usr
|
|
callback = CALLBACK(arglist(args))
|
|
INVOKE_ASYNC(src, PROC_REF(perform))
|
|
|
|
/datum/promise/proc/perform()
|
|
try
|
|
return_value = callback.Invoke()
|
|
status = PROMISE_RESOLVED
|
|
catch(var/exception/e)
|
|
runtime_message = e.name
|
|
status = PROMISE_REJECTED
|
|
|
|
#undef PROMISE_PENDING
|
|
#undef PROMISE_RESOLVED
|
|
#undef PROMISE_REJECTED
|