tylerneylon / lua_api_demo

An educational Lua module that can be used to teach or learn about Lua's C API.
85 stars 15 forks source link

Support lua_pushcclosure #3

Open SoniEx2 opened 7 years ago

SoniEx2 commented 7 years ago

lua_pushcclosure should push the parent lua_State as the first upvalue and a "function specifier" as the second upvalue.

the passed lua function should go on the parent lua_State's registry, and that's where the "function specifier" comes from.

lua_pushcclosure(function(L)
  print(L)
  print("virtualization!")
  return 0
end)

debug.* API wouldn't get much from those C closures, making this an effective sandbox.

tylerneylon commented 7 years ago

This general idea makes sense to me. I'll add it to my todo list and hopefully get to that soon. Thanks!