#ifndef UI_LUA_H #define UI_LUA_H #include "ui.h" // Registers the `ui`/`app` globals and input constants in the Lua state void ui_lua_register(lua_State* L); // Loads and runs a script file in its own sandboxed environment. Creation // and script execution are decoupled: this makes no container. The script // calls ui.create_overlay itself, from wherever it wants one — top level, // a dispatch handler, or a bus subscription callback, any of which may run // after this call returns, since app.subscribe can defer indefinitely. VkResult ui_lua_run_script( lua_State* L, UIContext* ui, RenderContext* gpu, const char* path); // The container an input dispatch is currently calling into; NULL outside // dispatch (top-level script execution, bus subscription callbacks) — those // contexts have no single "current" overlay, so ui.rect/ui.text require one // to have been created first. Container* ui_lua_current_container(lua_State* L); // Resolves an overlay handle argument (as returned by ui.create_overlay) to // its Container, raising a Lua error if the argument isn't an overlay // handle or its container was already destroyed. For bindings outside // ui_lua.c (e.g. editor_lua.c's camera:attach) that need to accept an // overlay handle without reaching into its opaque internals. Container* ui_lua_check_overlay(lua_State* L, int idx); // Points the binding's registry context at a container (or NULL) before // calling into a script from outside the normal dispatch path void ui_lua_set_current( lua_State* L, Container* c, UIContext* ui, RenderContext* gpu); // The script_env of whichever script is conceptually "running" right now — // the script executing its top level, the script owning the container an // input dispatch is calling into, or the script that registered the bus // subscription currently being delivered. Used to attribute new overlays // (ui.create_overlay) and new subscriptions (app.subscribe) to the right // script. LUA_NOREF if nothing is running (shouldn't happen in practice). int ui_lua_current_script(lua_State* L); void ui_lua_set_current_script(lua_State* L, int script_env); // Called by the engine input path. Each returns true if the container's script // defined the handler and it returned a truthy value (event consumed). The // handler receives the dispatching container's overlay handle as its first // argument, before element: a script's script_env may back more than one // container, so a shared on_button etc. needs to know which one fired. bool ui_lua_dispatch_button( UIContext* ui, RenderContext* gpu, Container* c, uint32_t element, float x, float y, int button, int action, int mods); bool ui_lua_dispatch_cursor( UIContext* ui, RenderContext* gpu, Container* c, uint32_t element, float x, float y); bool ui_lua_dispatch_scroll( UIContext* ui, RenderContext* gpu, Container* c, uint32_t element, double x, double y); bool ui_lua_dispatch_key( UIContext* ui, RenderContext* gpu, Container* c, uint32_t element, int key, int action, int mods); bool ui_lua_dispatch_text( UIContext* ui, RenderContext* gpu, Container* c, uint32_t element, unsigned int codepoint); bool ui_lua_dispatch_deselect( UIContext* ui, RenderContext* gpu, Container* c, uint32_t element); #endif