I am able to load a DLL created from C source from within Lua. So what I want to be able to do is pass the current Lua state FROM Lua to the loaded DLL.
Basically I’m using a game engine that uses Lua. The scene editor of said game engine creates the Lua state and calls Lua scripts and I know for a fact that it uses 1 lua state for all the scripts that it calls. So, I would imagine that state is known from within these lua scripts themselves. From within these Lua scripts I want to load my own DLL and pass in this state to that DLL, so my C++ code can use that lua state to call lua functions from the same lua scripts and be in the same state. Does that make sense?
I’m missing something obvious, I guess (which wouldn’t surprise me – I’m far from a Lua expert).
But if you call package.loadlib, the function handle you get back IS going to be called with the state by Lua itself, isn’t it? See the CFunction prototype