update project script methods, replace project script with project client script

This commit is contained in:
MihailRis
2025-08-18 21:20:18 +03:00
parent dc0e388eec
commit c8d760e83e
6 changed files with 92 additions and 88 deletions
+5 -6
View File
@@ -117,20 +117,19 @@ public:
}
};
class LuaProjectScript : public IProjectScript {
class LuaProjectScript : public IClientProjectScript {
public:
LuaProjectScript(lua::State* L, scriptenv env) : L(L), env(std::move(env)) {}
void onScreenChange(const std::string& name) override {
void onScreenChange(const std::string& name, bool show) override {
if (!lua::pushenv(L, *env)) {
return;
}
if (!lua::getfield(L, "on_screen_changed")) {
if (!lua::getfield(L, "on_" + name + (show ? "_setup" : "_clear"))) {
lua::pop(L);
return;
}
lua::pushlstring(L, name);
lua::call_nothrow(L, 1, 0);
lua::call_nothrow(L, 0, 0);
lua::pop(L);
}
private:
@@ -138,7 +137,7 @@ private:
scriptenv env;
};
std::unique_ptr<IProjectScript> scripting::load_project_script(
std::unique_ptr<IClientProjectScript> scripting::load_client_project_script(
const io::path& script
) {
auto L = lua::get_main_state();
+6 -4
View File
@@ -65,14 +65,16 @@ namespace scripting {
void process_post_runnables();
class IProjectScript {
class IClientProjectScript {
public:
virtual ~IProjectScript() {}
virtual ~IClientProjectScript() {}
virtual void onScreenChange(const std::string& name) = 0;
virtual void onScreenChange(const std::string& name, bool show) = 0;
};
std::unique_ptr<IProjectScript> load_project_script(const io::path& script);
std::unique_ptr<IClientProjectScript> load_client_project_script(
const io::path& script
);
std::unique_ptr<Process> start_coroutine(const io::path& script);