mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-08 20:41:49 +00:00
cleanup internal functions
This commit is contained in:
parent
39a3c1201f
commit
6c568e6706
8 changed files with 47 additions and 60 deletions
|
|
@ -636,6 +636,12 @@ namespace lua {
|
|||
int call(lua::State*, int argc, int nresults = -1);
|
||||
int call_nothrow(lua::State*, int argc, int nresults = 1);
|
||||
|
||||
inline void call_internal(lua::State* L, const std::string& name) {
|
||||
if (lua::get_from_registry(L, lua::INTERNALS_TABLE, name, true)) {
|
||||
lua::call_nothrow(L, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
inline int eval(
|
||||
lua::State* L,
|
||||
int env,
|
||||
|
|
|
|||
|
|
@ -65,14 +65,13 @@ int scripting::load_script(
|
|||
return lua::execute(lua::get_main_state(), env, src, fileName);
|
||||
}
|
||||
|
||||
void scripting::initialize(Engine* engine) {
|
||||
scripting::engine = engine;
|
||||
scripting::content_control = &engine->getContentControl();
|
||||
lua::initialize(engine->getPaths(), engine->getCoreParameters());
|
||||
void scripting::initialize(Engine& engine) {
|
||||
scripting::engine = &engine;
|
||||
scripting::content_control = &engine.getContentControl();
|
||||
lua::initialize(engine.getPaths(), engine.getCoreParameters());
|
||||
|
||||
load_script(io::path("stdlib.lua"), true);
|
||||
load_script(io::path("classes.lua"), true);
|
||||
load_script(io::path("internal_events.lua"), true);
|
||||
}
|
||||
|
||||
class LuaCoroutine : public Process {
|
||||
|
|
@ -244,9 +243,7 @@ std::unique_ptr<Process> scripting::start_app_script(const io::path& script) {
|
|||
|
||||
void scripting::process_post_runnables() {
|
||||
auto L = lua::get_main_state();
|
||||
if (lua::getglobal(L, "__vc__process_post_runnables")) {
|
||||
lua::call_nothrow(L, 0, 0);
|
||||
}
|
||||
lua::call_internal(L, "process_post_runnables");
|
||||
}
|
||||
|
||||
template <class T, typename IdType>
|
||||
|
|
@ -321,9 +318,7 @@ void scripting::on_world_load(LevelController* controller) {
|
|||
scripting::controller = controller;
|
||||
|
||||
auto L = lua::get_main_state();
|
||||
if (lua::getglobal(L, "__vc_on_world_open")) {
|
||||
lua::call_nothrow(L, 0, 0);
|
||||
}
|
||||
lua::call_internal(L, "on_world_open");
|
||||
|
||||
for (auto& pack : content_control->getAllContentPacks()) {
|
||||
lua::emit_event(L, pack.id + ":.worldopen", [](auto L) {
|
||||
|
|
@ -336,7 +331,7 @@ void scripting::on_world_load(LevelController* controller) {
|
|||
|
||||
void scripting::on_world_tick(int tps) {
|
||||
auto L = lua::get_main_state();
|
||||
if (lua::getglobal(L, "__vc_on_world_tick")) {
|
||||
if (lua::get_from_registry(L, lua::INTERNALS_TABLE, "on_world_tick", true)) {
|
||||
lua::pushinteger(L, tps);
|
||||
lua::call_nothrow(L, 1, 0);
|
||||
}
|
||||
|
|
@ -350,16 +345,12 @@ void scripting::on_world_save() {
|
|||
for (auto& pack : content_control->getAllContentPacks()) {
|
||||
lua::emit_event(L, pack.id + ":.worldsave");
|
||||
}
|
||||
if (lua::getglobal(L, "__vc_on_world_save")) {
|
||||
lua::call_nothrow(L, 0, 0);
|
||||
}
|
||||
lua::call_internal(L, "on_world_save");
|
||||
}
|
||||
|
||||
void scripting::process_before_quit() {
|
||||
auto L = lua::get_main_state();
|
||||
if (lua::getglobal(L, "__vc_process_before_quit")) {
|
||||
lua::call_nothrow(L, 0, 0);
|
||||
}
|
||||
lua::call_internal(L, "process_before_quit");
|
||||
}
|
||||
|
||||
void scripting::on_world_quit() {
|
||||
|
|
@ -367,9 +358,7 @@ void scripting::on_world_quit() {
|
|||
for (auto& pack : content_control->getAllContentPacks()) {
|
||||
lua::emit_event(L, pack.id + ":.worldquit");
|
||||
}
|
||||
if (lua::get_from_registry(L, lua::INTERNALS_TABLE, "on_world_quit", true)) {
|
||||
lua::call_nothrow(L, 0, 0);
|
||||
}
|
||||
lua::call_internal(L, "on_world_quit");
|
||||
scripting::level = nullptr;
|
||||
scripting::content = nullptr;
|
||||
scripting::indices = nullptr;
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ namespace scripting {
|
|||
extern std::ostream* output_stream;
|
||||
extern std::ostream* error_stream;
|
||||
|
||||
void initialize(Engine* engine);
|
||||
void initialize(Engine& engine);
|
||||
|
||||
void on_content_load(Content* content);
|
||||
void on_content_reset();
|
||||
|
|
|
|||
|
|
@ -47,9 +47,7 @@ void scripting::on_frontend_init(
|
|||
|
||||
load_script("hud_classes.lua");
|
||||
|
||||
if (lua::getglobal(L, "__vc_on_hud_open")) {
|
||||
lua::call_nothrow(L, 0, 0);
|
||||
}
|
||||
lua::call_internal(L, "on_hud_open");
|
||||
|
||||
for (auto& pack : content_control->getAllContentPacks()) {
|
||||
lua::emit_event(
|
||||
|
|
@ -65,9 +63,7 @@ void scripting::on_frontend_init(
|
|||
void scripting::on_frontend_render() {
|
||||
auto L = lua::get_main_state();
|
||||
|
||||
if (lua::get_from_registry(L, lua::INTERNALS_TABLE, "on_render", true)) {
|
||||
lua::call_nothrow(L, 0, 0);
|
||||
}
|
||||
lua::call_internal(L, "on_render");
|
||||
for (auto& pack : content_control->getAllContentPacks()) {
|
||||
lua::emit_event(L, pack.id + ":.hudrender", [](lua::State* L) {
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue