Created
February 28, 2017 18:56
-
-
Save postwait/0a0d9dd6c1d0fd07530489f240ca9ea2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool | |
BindingInstance::construct() | |
{ | |
ink_release_assert(this->lua == nullptr); | |
if ((this->lua = luaL_newstate())) { | |
luaL_openlibs(this->lua); | |
// Push a pointer to ourself into the well-known registry key. | |
// We do not use lightuserdata here because BindingInstance variables | |
// are often declared on stack which would make "this" a stack variable. | |
// While this might seem fine and actually work on many platforms, those | |
// 64bit platforms with split VA space where heap and stack may live in | |
// a separate 47bit VA will violate internal assumptions that luajit | |
// places on lightuserdata. Plain userdata will provide luajit-happy | |
// address in which we have the full 64bits to store our pointer to this. | |
// see: https://www.circonus.com/2016/07/luajit-illumos-vm/ | |
BindingInstance **lua_surrogate; | |
lua_surrogate = (BindingInstance **)lua_newuserdata(this->lua, sizeof(BindingInstance *)); | |
*lua_surrogate = this; | |
lua_setfield(this->lua, LUA_REGISTRYINDEX, selfkey); | |
ink_release_assert(BindingInstance::self(this->lua) == this); | |
} | |
return this->lua; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment