mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-12 06:21:50 +00:00
cleanup internal functions
This commit is contained in:
parent
ab179881e8
commit
629f672d38
6 changed files with 37 additions and 24 deletions
|
|
@ -540,20 +540,27 @@ function __vc_on_world_save()
|
||||||
file.write(RULES_FILE, toml.tostring(rule_values))
|
file.write(RULES_FILE, toml.tostring(rule_values))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local __close_all_descriptors = file.__close_all_descriptors
|
||||||
|
local __gui_util_reset_local = gui_util.__reset_local
|
||||||
|
local __stdcomp_reset = stdcomp.__reset
|
||||||
|
file.__close_all_descriptors = nil
|
||||||
|
gui_util.__reset_local = nil
|
||||||
|
stdcomp.reset = nil
|
||||||
|
|
||||||
function __vc_on_world_quit()
|
function __vc_on_world_quit()
|
||||||
_rules.clear()
|
_rules.clear()
|
||||||
gui_util:__reset_local()
|
__gui_util_reset_local()
|
||||||
stdcomp.__reset()
|
__stdcomp_reset()
|
||||||
file.__close_all_descriptors()
|
__close_all_descriptors()
|
||||||
end
|
end
|
||||||
|
|
||||||
local __post_runnables = {}
|
|
||||||
|
|
||||||
local fn_audio_reset_fetch_buffer = audio.__reset_fetch_buffer
|
local fn_audio_reset_fetch_buffer = audio.__reset_fetch_buffer
|
||||||
audio.__reset_fetch_buffer = nil
|
audio.__reset_fetch_buffer = nil
|
||||||
core.get_core_token = audio.input.__get_core_token
|
core.get_core_token = audio.input.__get_core_token
|
||||||
|
|
||||||
local function __vc__process_post_runnables()
|
local __post_runnables = {}
|
||||||
|
|
||||||
|
local function __process_post_runnables()
|
||||||
if #__post_runnables > 0 then
|
if #__post_runnables > 0 then
|
||||||
for _, func in ipairs(__post_runnables) do
|
for _, func in ipairs(__post_runnables) do
|
||||||
local status, result = xpcall(func, __vc__error)
|
local status, result = xpcall(func, __vc__error)
|
||||||
|
|
@ -587,9 +594,9 @@ local function __vc__process_post_runnables()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function __process_post_runnables()
|
function __vc__process_post_runnables()
|
||||||
__vc__is_post_runnable = true
|
__vc__is_post_runnable = true
|
||||||
local success, err = pcall(__vc__process_post_runnables)
|
local success, err = pcall(__process_post_runnables)
|
||||||
if not success then
|
if not success then
|
||||||
debug.error("an error ocurred while processing post-runnables: ".. err)
|
debug.error("an error ocurred while processing post-runnables: ".. err)
|
||||||
end
|
end
|
||||||
|
|
@ -624,3 +631,4 @@ require "core:internal/deprecated"
|
||||||
ffi = nil
|
ffi = nil
|
||||||
__vc_app = nil
|
__vc_app = nil
|
||||||
__vc_lock_internal_modules()
|
__vc_lock_internal_modules()
|
||||||
|
__vc_lock_internal_modules = nil
|
||||||
|
|
|
||||||
|
|
@ -192,7 +192,7 @@ function reload_module(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local internal_locked = false
|
local __internal_locked = false
|
||||||
|
|
||||||
-- Load script with caching
|
-- Load script with caching
|
||||||
--
|
--
|
||||||
|
|
@ -202,9 +202,12 @@ local internal_locked = false
|
||||||
-- nocache - ignore cached script, load anyway
|
-- nocache - ignore cached script, load anyway
|
||||||
function __load_script(path, nocache, env)
|
function __load_script(path, nocache, env)
|
||||||
local packname, filename = parse_path(path)
|
local packname, filename = parse_path(path)
|
||||||
|
local is_internal = (packname == "res" or packname == "core")
|
||||||
|
and filename:find("modules/internal") == 1
|
||||||
|
|
||||||
if internal_locked and (packname == "res" or packname == "core")
|
nocache = nocache or is_internal
|
||||||
and filename:starts_with("modules/internal") then
|
|
||||||
|
if is_internal and __internal_locked then
|
||||||
error("access to core:internal modules outside of [core]")
|
error("access to core:internal modules outside of [core]")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -232,16 +235,19 @@ function __load_script(path, nocache, env)
|
||||||
end
|
end
|
||||||
|
|
||||||
function __vc_lock_internal_modules()
|
function __vc_lock_internal_modules()
|
||||||
internal_locked = true
|
__internal_locked = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local __pack_envs = __vc__pack_envs
|
||||||
|
__vc__pack_envs = nil
|
||||||
|
|
||||||
function require(path)
|
function require(path)
|
||||||
if not string.find(path, ':') then
|
if not string.find(path, ':') then
|
||||||
local prefix, _ = parse_path(_debug_getinfo(2).source)
|
local prefix, _ = parse_path(_debug_getinfo(2).source)
|
||||||
return require(prefix .. ':' .. path)
|
return require(prefix .. ':' .. path)
|
||||||
end
|
end
|
||||||
local prefix, file = parse_path(path)
|
local prefix, file = parse_path(path)
|
||||||
local env = __vc__pack_envs[prefix]
|
local env = __pack_envs[prefix]
|
||||||
return __load_script(prefix .. ":modules/" .. file .. ".lua", nil, env)
|
return __load_script(prefix .. ":modules/" .. file .. ".lua", nil, env)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -262,7 +268,7 @@ function __scripts_cleanup(non_reset_packs)
|
||||||
__cached_scripts[k] = nil
|
__cached_scripts[k] = nil
|
||||||
package.loaded[k] = nil
|
package.loaded[k] = nil
|
||||||
end
|
end
|
||||||
__vc__pack_envs[packname] = nil
|
__pack_envs[packname] = nil
|
||||||
::continue::
|
::continue::
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,9 @@ void lua::init_state(State* L, StateType stateType) {
|
||||||
setglobal(L, "io");
|
setglobal(L, "io");
|
||||||
|
|
||||||
createtable(L, 0, 0);
|
createtable(L, 0, 0);
|
||||||
|
pushvalue(L, -1);
|
||||||
setglobal(L, "__vc__pack_envs");
|
setglobal(L, "__vc__pack_envs");
|
||||||
|
setregistry(L, lua::PACK_ENVS_TABLE);
|
||||||
|
|
||||||
const char* removed_os[] {
|
const char* removed_os[] {
|
||||||
"execute", "exit", "remove", "rename", "setlocale", "tmpname", nullptr};
|
"execute", "exit", "remove", "rename", "setlocale", "tmpname", nullptr};
|
||||||
|
|
|
||||||
|
|
@ -220,7 +220,7 @@ void lua::dump_stack(State* L) {
|
||||||
static std::shared_ptr<std::string> create_lambda_handler(State* L) {
|
static std::shared_ptr<std::string> create_lambda_handler(State* L) {
|
||||||
auto ptr = reinterpret_cast<ptrdiff_t>(topointer(L, -1));
|
auto ptr = reinterpret_cast<ptrdiff_t>(topointer(L, -1));
|
||||||
auto name = util::mangleid(ptr);
|
auto name = util::mangleid(ptr);
|
||||||
reguireregistry(L, LAMBDAS_TABLE);
|
requireregistry(L, LAMBDAS_TABLE);
|
||||||
pushvalue(L, -2);
|
pushvalue(L, -2);
|
||||||
setfield(L, name);
|
setfield(L, name);
|
||||||
pop(L, 2);
|
pop(L, 2);
|
||||||
|
|
@ -229,7 +229,7 @@ static std::shared_ptr<std::string> create_lambda_handler(State* L) {
|
||||||
new std::string(name),
|
new std::string(name),
|
||||||
[=](std::string* name) {
|
[=](std::string* name) {
|
||||||
auto L = lua::get_main_state();
|
auto L = lua::get_main_state();
|
||||||
reguireregistry(L, LAMBDAS_TABLE);
|
requireregistry(L, LAMBDAS_TABLE);
|
||||||
pushnil(L);
|
pushnil(L);
|
||||||
setfield(L, *name);
|
setfield(L, *name);
|
||||||
pop(L);
|
pop(L);
|
||||||
|
|
@ -341,7 +341,7 @@ int lua::create_environment(State* L, int parent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int lua::restore_pack_environment(lua::State* L, const std::string& packid) {
|
int lua::restore_pack_environment(lua::State* L, const std::string& packid) {
|
||||||
if(!lua::getglobal(L, "__vc__pack_envs")) {
|
if(!lua::requireregistry(L, lua::PACK_ENVS_TABLE)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int id = nextEnvironment++;
|
int id = nextEnvironment++;
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
namespace lua {
|
namespace lua {
|
||||||
inline std::string LAMBDAS_TABLE = "$L"; // lambdas storage
|
inline std::string LAMBDAS_TABLE = "$L"; // lambdas storage
|
||||||
inline std::string CHUNKS_TABLE = "$C"; // precompiled lua chunks
|
inline std::string CHUNKS_TABLE = "$C"; // precompiled lua chunks
|
||||||
|
inline std::string PACK_ENVS_TABLE = "$P";
|
||||||
extern std::unordered_map<std::type_index, std::string> usertypeNames;
|
extern std::unordered_map<std::type_index, std::string> usertypeNames;
|
||||||
int userdata_destructor(lua::State* L);
|
int userdata_destructor(lua::State* L);
|
||||||
|
|
||||||
|
|
@ -49,7 +50,7 @@ namespace lua {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int reguireregistry(lua::State* L, const std::string& name) {
|
inline int requireregistry(lua::State* L, const std::string& name) {
|
||||||
if (getregistry(L, name)) {
|
if (getregistry(L, name)) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -188,11 +188,7 @@ std::unique_ptr<Process> scripting::start_app_script(const io::path& script) {
|
||||||
lua::pushstring(L, pack.id);
|
lua::pushstring(L, pack.id);
|
||||||
lua::setfield(L, "PACK_ID");
|
lua::setfield(L, "PACK_ID");
|
||||||
|
|
||||||
if(!lua::getglobal(L, "__vc__pack_envs")) {
|
lua::requireregistry(L, lua::PACK_ENVS_TABLE);
|
||||||
lua::createtable(L, 0, 0);
|
|
||||||
lua::setglobal(L, "__vc__pack_envs");
|
|
||||||
lua::pushvalue(L, -1);
|
|
||||||
}
|
|
||||||
lua::pushenv(L, id);
|
lua::pushenv(L, id);
|
||||||
lua::setfield(L, pack.id);
|
lua::setfield(L, pack.id);
|
||||||
lua::pop(L);
|
lua::pop(L);
|
||||||
|
|
@ -248,7 +244,7 @@ std::unique_ptr<Process> scripting::start_app_script(const io::path& script) {
|
||||||
|
|
||||||
void scripting::process_post_runnables() {
|
void scripting::process_post_runnables() {
|
||||||
auto L = lua::get_main_state();
|
auto L = lua::get_main_state();
|
||||||
if (lua::getglobal(L, "__process_post_runnables")) {
|
if (lua::getglobal(L, "__vc__process_post_runnables")) {
|
||||||
lua::call_nothrow(L, 0, 0);
|
lua::call_nothrow(L, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue