summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/sol2/sol/state_view.hpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/sol2/sol/state_view.hpp')
-rw-r--r--3rdparty/sol2/sol/state_view.hpp35
1 files changed, 25 insertions, 10 deletions
diff --git a/3rdparty/sol2/sol/state_view.hpp b/3rdparty/sol2/sol/state_view.hpp
index d3c12d3bd4a..14032d65ac5 100644
--- a/3rdparty/sol2/sol/state_view.hpp
+++ b/3rdparty/sol2/sol/state_view.hpp
@@ -45,6 +45,13 @@ namespace sol {
count
};
+ inline std::size_t total_memory_used(lua_State* L) {
+ std::size_t kb = lua_gc(L, LUA_GCCOUNT, 0);
+ kb *= 1024;
+ kb += lua_gc(L, LUA_GCCOUNTB, 0);
+ return kb;
+ }
+
class state_view {
private:
lua_State* L;
@@ -108,14 +115,14 @@ namespace sol {
typedef global_table::iterator iterator;
typedef global_table::const_iterator const_iterator;
- state_view(lua_State* L) :
- L(L),
- reg(L, LUA_REGISTRYINDEX),
- global(L, detail::global_) {
+ state_view(lua_State* Ls) :
+ L(Ls),
+ reg(Ls, LUA_REGISTRYINDEX),
+ global(Ls, detail::global_) {
}
- state_view(this_state L) : state_view(L.L){
+ state_view(this_state Ls) : state_view(Ls.L){
}
@@ -153,7 +160,7 @@ namespace sol {
lua_pop(L, 1);
#endif // Lua 5.2+ only
break;
-#endif // Not LuaJIT
+#endif // Not LuaJIT - comes builtin
case lib::string:
luaL_requiref(L, "string", luaopen_string, 1);
lua_pop(L, 1);
@@ -170,11 +177,11 @@ namespace sol {
#ifdef SOL_LUAJIT
luaL_requiref(L, "bit32", luaopen_bit, 1);
lua_pop(L, 1);
-#elif SOL_LUA_VERSION == 502
+#elif (SOL_LUA_VERSION == 502) || defined(LUA_COMPAT_BITLIB) || defined(LUA_COMPAT_5_2)
luaL_requiref(L, "bit32", luaopen_bit32, 1);
lua_pop(L, 1);
#else
-#endif // Lua 5.2 only (deprecated in 5.3 (503))
+#endif // Lua 5.2 only (deprecated in 5.3 (503)) (Can be turned on with Compat flags)
break;
case lib::io:
luaL_requiref(L, "io", luaopen_io, 1);
@@ -198,13 +205,13 @@ namespace sol {
#ifdef SOL_LUAJIT
luaL_requiref(L, "ffi", luaopen_ffi, 1);
lua_pop(L, 1);
-#endif
+#endif // LuaJIT only
break;
case lib::jit:
#ifdef SOL_LUAJIT
luaL_requiref(L, "jit", luaopen_jit, 1);
lua_pop(L, 1);
-#endif
+#endif // LuaJIT Only
break;
case lib::count:
default:
@@ -291,6 +298,14 @@ namespace sol {
return reg;
}
+ std::size_t memory_used() const {
+ return total_memory_used(lua_state());
+ }
+
+ void collect_garbage() {
+ lua_gc(lua_state(), LUA_GCCOLLECT, 0);
+ }
+
operator lua_State* () const {
return lua_state();
}