Lua: Fix bug with methods and resetting Lua VM
This commit is contained in:
parent
5d08c36390
commit
8c346c0695
6 changed files with 24 additions and 9 deletions
|
@ -258,6 +258,8 @@ again:
|
|||
lua_class& operator=(const lua_class<T>&);
|
||||
};
|
||||
|
||||
bool lua_do_once(lua_State* LS, void* key);
|
||||
|
||||
#define DECLARE_LUACLASS(x, X) template<> lua_class< x >& objclass() { static lua_class< x > clazz( X ); \
|
||||
return clazz; }
|
||||
|
||||
|
|
|
@ -3588,7 +3588,7 @@ Warning: If the region crosses VMA boundary, the results are undefined.
|
|||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
memory.map_struct()
|
||||
memory.map_structure()
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
|
|
|
@ -1832,7 +1832,7 @@ Write a region of memory.
|
|||
• Warning: If the region crosses VMA boundary, the results are
|
||||
undefined.
|
||||
|
||||
8.9.21 memory.map_struct()
|
||||
8.9.21 memory.map_structure()
|
||||
|
||||
Returns a new mapping structure (MMAP_STRUCT)
|
||||
|
||||
|
|
|
@ -86,10 +86,9 @@ namespace
|
|||
lua_customfont::lua_customfont(lua_State* LS, const std::string& filename)
|
||||
: font(filename)
|
||||
{
|
||||
static bool done = false;
|
||||
if(!done) {
|
||||
static char done_key;
|
||||
if(lua_do_once(LS, &done_key)) {
|
||||
objclass<lua_customfont>().bind(LS, "__call", &lua_customfont::draw);
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -612,6 +612,21 @@ void lua_callback_do_unsafe_rewind(const std::vector<char>& save, uint64_t secs,
|
|||
}
|
||||
}
|
||||
|
||||
bool lua_do_once(lua_State* LS, void* key)
|
||||
{
|
||||
lua_pushlightuserdata(LS, key);
|
||||
lua_rawget(LS, LUA_REGISTRYINDEX);
|
||||
if(lua_type(LS, -1) == LUA_TNIL) {
|
||||
lua_pop(LS, 1);
|
||||
lua_pushlightuserdata(LS, key);
|
||||
lua_pushlightuserdata(LS, key);
|
||||
lua_rawset(LS, LUA_REGISTRYINDEX);
|
||||
return true;
|
||||
} else {
|
||||
lua_pop(LS, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool lua_requests_repaint = false;
|
||||
bool lua_requests_subframe_paint = false;
|
||||
|
|
|
@ -407,11 +407,10 @@ DECLARE_LUACLASS(lua_mmap_struct, "MMAP_STRUCT");
|
|||
|
||||
lua_mmap_struct::lua_mmap_struct(lua_State* LS)
|
||||
{
|
||||
static bool done = false;
|
||||
if(!done) {
|
||||
static char done_key;
|
||||
if(lua_do_once(LS, &done_key)) {
|
||||
objclass<lua_mmap_struct>().bind(LS, "__index", &lua_mmap_struct::index, true);
|
||||
objclass<lua_mmap_struct>().bind(LS, "__newindex", &lua_mmap_struct::newindex, true);
|
||||
objclass<lua_mmap_struct>().bind(LS, "__call", &lua_mmap_struct::map);
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue