summaryrefslogtreecommitdiff
path: root/src/util.rs
diff options
context:
space:
mode:
authorAlex Orlenko <zxteam@protonmail.com>2020-05-27 01:15:59 +0100
committerAlex Orlenko <zxteam@protonmail.com>2020-06-06 16:07:16 +0100
commitd5c22d989a27b169fa85d6a5ef87a752af2d8236 (patch)
treee847f166520557ca83065184b6a1e488e1e7cc88 /src/util.rs
parenta9a4cf13f18582f8300d1666f95dc13f71b07d55 (diff)
downloadmlua-d5c22d989a27b169fa85d6a5ef87a752af2d8236.zip
Dirty hack to get lua 5.1 main state
Diffstat (limited to 'src/util.rs')
-rw-r--r--src/util.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/util.rs b/src/util.rs
index eba93e9..d729155 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -493,7 +493,19 @@ pub unsafe fn get_main_state(state: *mut ffi::lua_State) -> *mut ffi::lua_State
ffi::lua_pop(state, 1);
main_state
}
- #[cfg(any(feature = "lua51", feature = "luajit"))]
+ #[cfg(feature = "lua51")]
+ {
+ // Check the current state first
+ let is_main_state = ffi::lua_pushthread(state) == 1;
+ ffi::lua_pop(state, 1);
+ if is_main_state {
+ state
+ } else {
+ // The function below is a dirty hack and uses Lua private internals
+ ffi::lua_getmainstate(state)
+ }
+ }
+ #[cfg(feature = "luajit")]
state
}