add on_screen_change project script event & fix UIDocument::rebuildIndices & move menu background to project script

This commit is contained in:
MihailRis
2025-08-07 22:14:52 +03:00
parent 7749da4a85
commit 0a02d3fbec
16 changed files with 148 additions and 66 deletions
+33 -2
View File
@@ -116,11 +116,42 @@ public:
}
};
std::unique_ptr<Process> scripting::start_coroutine(
class LuaProjectScript : public IProjectScript {
public:
LuaProjectScript(lua::State* L, scriptenv env) : L(L), env(std::move(env)) {}
void onScreenChange(const std::string& name) override {
if (!lua::pushenv(L, *env)) {
return;
}
if (!lua::getfield(L, "on_screen_changed")) {
lua::pop(L);
return;
}
lua::pushlstring(L, name);
lua::call_nothrow(L, 1, 0);
lua::pop(L);
}
private:
lua::State* L;
scriptenv env;
};
std::unique_ptr<IProjectScript> scripting::load_project_script(
const io::path& script
) {
auto L = lua::get_main_state();
if (lua::getglobal(L, "__vc_start_coroutine")) {
auto source = io::read_string(script);
auto env = create_environment(nullptr);
lua::loadbuffer(L, *env, source, script.name());
lua::call(L, 0);
return std::make_unique<LuaProjectScript>(L, std::move(env));
}
std::unique_ptr<Process> scripting::start_coroutine(const io::path& script) {
auto L = lua::get_main_state();
auto method = "__vc_start_coroutine";
if (lua::getglobal(L, method)) {
auto source = io::read_string(script);
lua::loadbuffer(L, 0, source, script.name());
if (lua::call(L, 1)) {