cleanup internal functions

This commit is contained in:
MihailRis 2026-04-27 00:24:25 +03:00
parent ab179881e8
commit 629f672d38
6 changed files with 37 additions and 24 deletions

View file

@ -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};

View file

@ -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++;

View file

@ -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 {

View file

@ -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);
}
}