Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.