Add string.buffer
to Lua environment (if it exists)
This commit is contained in:
parent
17f710bfd5
commit
c658140b4b
@ -97,6 +97,33 @@ ScriptApiBase::ScriptApiBase(ScriptingType type):
|
|||||||
lua_call(m_luastack, 0, 1);
|
lua_call(m_luastack, 0, 1);
|
||||||
lua_setglobal(m_luastack, "chacha");
|
lua_setglobal(m_luastack, "chacha");
|
||||||
|
|
||||||
|
// Load string.buffer if it is in package.preload
|
||||||
|
lua_getglobal(m_luastack, "package");
|
||||||
|
lua_getfield(m_luastack, -1, "preload");
|
||||||
|
lua_getfield(m_luastack, -1, "string.buffer");
|
||||||
|
if (!lua_isnil(m_luastack, -1)) {
|
||||||
|
// string.buffer = require("string.buffer")
|
||||||
|
lua_getglobal(m_luastack, "string");
|
||||||
|
lua_getglobal(m_luastack, "require");
|
||||||
|
lua_pushstring(m_luastack, "string.buffer");
|
||||||
|
lua_call(m_luastack, 1, 1);
|
||||||
|
lua_setfield(m_luastack, -2, "buffer");
|
||||||
|
lua_pop(m_luastack, 1); // Pop string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pop package, package.preload, and package.preload["string.buffer"]
|
||||||
|
lua_pop(m_luastack, 3);
|
||||||
|
|
||||||
|
// Delete references to package on the client (as they're no longer needed)
|
||||||
|
if (m_type == ScriptingType::Client) {
|
||||||
|
lua_pushnil(m_luastack);
|
||||||
|
lua_setglobal(m_luastack, "module");
|
||||||
|
lua_pushnil(m_luastack);
|
||||||
|
lua_setglobal(m_luastack, "require");
|
||||||
|
lua_pushnil(m_luastack);
|
||||||
|
lua_setglobal(m_luastack, "package");
|
||||||
|
}
|
||||||
|
|
||||||
// Make the ScriptApiBase* accessible to ModApiBase
|
// Make the ScriptApiBase* accessible to ModApiBase
|
||||||
#if INDIRECT_SCRIPTAPI_RIDX
|
#if INDIRECT_SCRIPTAPI_RIDX
|
||||||
*(void **)(lua_newuserdata(m_luastack, sizeof(void *))) = this;
|
*(void **)(lua_newuserdata(m_luastack, sizeof(void *))) = this;
|
||||||
@ -160,6 +187,7 @@ void ScriptApiBase::clientOpenLibs(lua_State *L)
|
|||||||
{ LUA_STRLIBNAME, luaopen_string },
|
{ LUA_STRLIBNAME, luaopen_string },
|
||||||
{ LUA_MATHLIBNAME, luaopen_math },
|
{ LUA_MATHLIBNAME, luaopen_math },
|
||||||
{ LUA_DBLIBNAME, luaopen_debug },
|
{ LUA_DBLIBNAME, luaopen_debug },
|
||||||
|
{ LUA_LOADLIBNAME, luaopen_package },
|
||||||
#if USE_LUAJIT
|
#if USE_LUAJIT
|
||||||
{ LUA_JITLIBNAME, luaopen_jit },
|
{ LUA_JITLIBNAME, luaopen_jit },
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user