mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +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))
|
||||
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()
|
||||
_rules.clear()
|
||||
gui_util:__reset_local()
|
||||
stdcomp.__reset()
|
||||
file.__close_all_descriptors()
|
||||
__gui_util_reset_local()
|
||||
__stdcomp_reset()
|
||||
__close_all_descriptors()
|
||||
end
|
||||
|
||||
local __post_runnables = {}
|
||||
|
||||
local fn_audio_reset_fetch_buffer = audio.__reset_fetch_buffer
|
||||
audio.__reset_fetch_buffer = nil
|
||||
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
|
||||
for _, func in ipairs(__post_runnables) do
|
||||
local status, result = xpcall(func, __vc__error)
|
||||
|
|
@ -587,9 +594,9 @@ local function __vc__process_post_runnables()
|
|||
end
|
||||
end
|
||||
|
||||
function __process_post_runnables()
|
||||
function __vc__process_post_runnables()
|
||||
__vc__is_post_runnable = true
|
||||
local success, err = pcall(__vc__process_post_runnables)
|
||||
local success, err = pcall(__process_post_runnables)
|
||||
if not success then
|
||||
debug.error("an error ocurred while processing post-runnables: ".. err)
|
||||
end
|
||||
|
|
@ -624,3 +631,4 @@ require "core:internal/deprecated"
|
|||
ffi = nil
|
||||
__vc_app = nil
|
||||
__vc_lock_internal_modules()
|
||||
__vc_lock_internal_modules = nil
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ function reload_module(name)
|
|||
end
|
||||
end
|
||||
|
||||
local internal_locked = false
|
||||
local __internal_locked = false
|
||||
|
||||
-- Load script with caching
|
||||
--
|
||||
|
|
@ -202,9 +202,12 @@ local internal_locked = false
|
|||
-- nocache - ignore cached script, load anyway
|
||||
function __load_script(path, nocache, env)
|
||||
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")
|
||||
and filename:starts_with("modules/internal") then
|
||||
nocache = nocache or is_internal
|
||||
|
||||
if is_internal and __internal_locked then
|
||||
error("access to core:internal modules outside of [core]")
|
||||
end
|
||||
|
||||
|
|
@ -232,16 +235,19 @@ function __load_script(path, nocache, env)
|
|||
end
|
||||
|
||||
function __vc_lock_internal_modules()
|
||||
internal_locked = true
|
||||
__internal_locked = true
|
||||
end
|
||||
|
||||
local __pack_envs = __vc__pack_envs
|
||||
__vc__pack_envs = nil
|
||||
|
||||
function require(path)
|
||||
if not string.find(path, ':') then
|
||||
local prefix, _ = parse_path(_debug_getinfo(2).source)
|
||||
return require(prefix .. ':' .. path)
|
||||
end
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
@ -262,7 +268,7 @@ function __scripts_cleanup(non_reset_packs)
|
|||
__cached_scripts[k] = nil
|
||||
package.loaded[k] = nil
|
||||
end
|
||||
__vc__pack_envs[packname] = nil
|
||||
__pack_envs[packname] = nil
|
||||
::continue::
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -113,7 +113,9 @@ void lua::init_state(State* L, StateType stateType) {
|
|||
setglobal(L, "io");
|
||||
|
||||
createtable(L, 0, 0);
|
||||
pushvalue(L, -1);
|
||||
setglobal(L, "__vc__pack_envs");
|
||||
setregistry(L, lua::PACK_ENVS_TABLE);
|
||||
|
||||
const char* removed_os[] {
|
||||
"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) {
|
||||
auto ptr = reinterpret_cast<ptrdiff_t>(topointer(L, -1));
|
||||
auto name = util::mangleid(ptr);
|
||||
reguireregistry(L, LAMBDAS_TABLE);
|
||||
requireregistry(L, LAMBDAS_TABLE);
|
||||
pushvalue(L, -2);
|
||||
setfield(L, name);
|
||||
pop(L, 2);
|
||||
|
|
@ -229,7 +229,7 @@ static std::shared_ptr<std::string> create_lambda_handler(State* L) {
|
|||
new std::string(name),
|
||||
[=](std::string* name) {
|
||||
auto L = lua::get_main_state();
|
||||
reguireregistry(L, LAMBDAS_TABLE);
|
||||
requireregistry(L, LAMBDAS_TABLE);
|
||||
pushnil(L);
|
||||
setfield(L, *name);
|
||||
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) {
|
||||
if(!lua::getglobal(L, "__vc__pack_envs")) {
|
||||
if(!lua::requireregistry(L, lua::PACK_ENVS_TABLE)) {
|
||||
return -1;
|
||||
}
|
||||
int id = nextEnvironment++;
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
namespace lua {
|
||||
inline std::string LAMBDAS_TABLE = "$L"; // lambdas storage
|
||||
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;
|
||||
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)) {
|
||||
return 1;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -188,11 +188,7 @@ std::unique_ptr<Process> scripting::start_app_script(const io::path& script) {
|
|||
lua::pushstring(L, pack.id);
|
||||
lua::setfield(L, "PACK_ID");
|
||||
|
||||
if(!lua::getglobal(L, "__vc__pack_envs")) {
|
||||
lua::createtable(L, 0, 0);
|
||||
lua::setglobal(L, "__vc__pack_envs");
|
||||
lua::pushvalue(L, -1);
|
||||
}
|
||||
lua::requireregistry(L, lua::PACK_ENVS_TABLE);
|
||||
lua::pushenv(L, id);
|
||||
lua::setfield(L, pack.id);
|
||||
lua::pop(L);
|
||||
|
|
@ -248,7 +244,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, "__process_post_runnables")) {
|
||||
if (lua::getglobal(L, "__vc__process_post_runnables")) {
|
||||
lua::call_nothrow(L, 0, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue