fix(lua): make core vim module not dependent on $VIMRUNTIME functions

fixes #15524

Note: this is obviously a quickfix. A scalabe solution will
involve being able to specify a _list_ of modules to be
put into packages.preload, without needing to manually copypasta
a blurb of C code. Perhaps even involving bytecode for
static builds (to speedup initialization)
This commit is contained in:
Björn Linse
2021-08-30 17:31:44 +02:00
parent 3ab73ff81f
commit 6f2d0ea311
3 changed files with 32 additions and 3 deletions

View File

@@ -544,8 +544,17 @@ static int nlua_state_init(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
return 1;
}
// [package, loaded, inspect]
lua_setfield(lstate, -2, "vim.inspect"); // [package, loaded]
code = (char *)&lua_F_module[0];
if (luaL_loadbuffer(lstate, code, strlen(code), "@vim/F.lua")
|| lua_pcall(lstate, 0, 1, 0)) {
nlua_error(lstate, _("E5106: Error while creating vim.F module: %.*s"));
return 1;
}
// [package, loaded, module]
lua_setfield(lstate, -2, "vim.F"); // [package, loaded]
lua_pop(lstate, 2); // []
}
@@ -558,6 +567,22 @@ static int nlua_state_init(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
}
}
{
lua_getglobal(lstate, "package"); // [package]
lua_getfield(lstate, -1, "loaded"); // [package, loaded]
const char *code = (char *)&lua_meta_module[0];
if (luaL_loadbuffer(lstate, code, strlen(code), "@vim/_meta.lua")
|| lua_pcall(lstate, 0, 1, 0)) {
nlua_error(lstate, _("E5106: Error while creating vim._meta module: %.*s"));
return 1;
}
// [package, loaded, module]
lua_setfield(lstate, -2, "vim._meta"); // [package, loaded]
lua_pop(lstate, 2); // []
}
return 0;
}