`local globalstate` is initialised to have the field `suppressed_players`, but the non-existent field `suppress` is requested, resulting in operations on nil rather than the expected table. This causes the aforementioned crash.
This commit fixes this issue.
Also update //for to make use of this new functionality.
//subdivide is still on the todo list.
The new functionality works by adding the new property `async = false` to command definition tables registered via wea_core.register_command()`. When `true`, if and only if the command's MAIN FUNC ONLY returns no values at all then it will consider an async operation to be in progress.
This delays `run_command` from emitting the `post-execute` event on `wea_core`.
Additionally, all async commands have a callback function injected as the first argument to their main `func` (ref main cmd definition table). This callback function -- if no arguments are returned by the main `func` -- must be called once the async operation is complete with same args you would normally return from `func` -- that is `success, result_message`. These will then be handled as normal and sent to the player as appropriate, as well as finally emitting the `post-execute` event.
BUG: There is a potential issue in this implementation, in that if i.e. `minetest.after()` is used to delay async execution then this will break out of the `xpcall()` protection in place to prevent crashes. To this end, if you implement an async function you need to be very careful, and do a manual `wea_core.safe_function()` call yourself!
When you do weac.notify(player_name, "info", "msg"), Lua auto-inserts a `self` table which refers to the main `Notify` table there.
This is because `local function call()` is registered via `setmetatable(Notify, ...)`, which auto-inserts `self` as the 1st argument.
To this end, this command adds a dummy 1st argument `_self` to capture this extra table to avoid all args being shifted by 1.
....it works, but:
- We can't capture stack traces like this
- It's messy
- We need to implement an escape/encodeURIComponent function ourselves from scratch 'cause the one I ripped from Stack Overflow sucks