1

I've been attempting to change the address of a Lua Closure and then use a wrapping function which requires the upvalue of the function be passed to it. The only issue is when I change the address of the function and try to move over the upvalue it fails as the closure has no allocated space for any upvalues. So the question is, is there a way to allocate space for an upvalue for a closure which has already been created? In coding this would look like

lua_pushnil(L);//For example
lua_pushcclosure(L, Function, 0);
lua_addupvalue(L, -1, 1);
lua_pushvalue(L, -2);
lua_setupvalue(L, -2, 1);

That's the kind of method I would like, I hope the arguments are self explanatory. If anyone has any ideas please let me know. I've been pondering this for a while now.

  • 2
    If the closure was created with no parameters at all, it's not gonna be created as a closure at all, so that's already problematic. If it _was_ indeed a closure, but you'd like to append something to it, you'd probably need to reallocate it; `luaF_newCclosure` allocates precise amount of space given when creating it. Your best bet is to create a closure with a dummy value and then just change that dummy value later. – Bartek Banachewicz May 25 '20 at 18:34
  • @BartekBanachewicz That should be an answer. – Joseph Sible-Reinstate Monica May 30 '20 at 16:42

0 Answers0