]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/script/cpp_api/s_base.cpp
Merge branch 'master' of https://github.com/minetest/minetest
[dragonfireclient.git] / src / script / cpp_api / s_base.cpp
index 27d730b1d89248936db806acf5331ea4ff28007d..ae4a1677156b88b6d1021a23cdde300f1b70da3f 100644 (file)
@@ -38,6 +38,8 @@ extern "C" {
 #include "lualib.h"
 #if USE_LUAJIT
        #include "luajit.h"
+#else
+       #include "bit.h"
 #endif
 }
 
@@ -89,6 +91,11 @@ ScriptApiBase::ScriptApiBase(ScriptingType type):
        else*/
                luaL_openlibs(m_luastack);
 
+       // Load bit library
+       lua_pushcfunction(m_luastack, luaopen_bit);
+       lua_pushstring(m_luastack, LUA_BITLIBNAME);
+       lua_call(m_luastack, 1, 0);
+
        // Make the ScriptApiBase* accessible to ModApiBase
 #if INDIRECT_SCRIPTAPI_RIDX
        *(void **)(lua_newuserdata(m_luastack, sizeof(void *))) = this;
@@ -115,6 +122,14 @@ ScriptApiBase::ScriptApiBase(ScriptingType type):
        lua_newtable(m_luastack);
        lua_setglobal(m_luastack, "core");
 
+       // vector.metatable is stored in the registry for quick access from C++.
+       lua_newtable(m_luastack);
+       lua_rawseti(m_luastack, LUA_REGISTRYINDEX, CUSTOM_RIDX_VECTOR_METATABLE);
+       lua_newtable(m_luastack);
+       lua_rawgeti(m_luastack, LUA_REGISTRYINDEX, CUSTOM_RIDX_VECTOR_METATABLE);
+       lua_setfield(m_luastack, -2, "metatable");
+       lua_setglobal(m_luastack, "vector");
+
        if (m_type == ScriptingType::Client)
                lua_pushstring(m_luastack, "/");
        else