On Sun, Mar 16, 2014 at 1:58 AM, steve donovan
<steve.j.donovan@gmail.com> wrote:
On Sat, Mar 15, 2014 at 8:53 PM, Liam Devine <
liamdevine@oolua.org> wrote:
> this thread is about, could it be to announce a higher level API for C
> programmers for whom stack operations give them a headache!
That's a fair summary, they do give me a headache. This is not a
fault of the Lua API itself.
Sorry if I've got a bit ... obsessive about C++. (I've never been the
same after writing UnderC)
To me, C/C++ are tools for making libraries to allow Lua to do what I want. ;-) When I use them, usually I don't use any C++ features beyond templates and classes.
I agree that working with the Lua stack can be a headache at times. It helps a lot to annotate each stack operation with a comment listing the stack contents, like:
lua_getmetatable(Lua, 1); //-1: meta
lua_getfield (Lua, -1, "method"); //-1: method, -2: meta
lua_pushvalue(Lua, 2); //-1: key, -2: method, -3: meta
lua_gettable (Lua, -2); //-1: value, -2: method, -3: meta
But it can still be difficult to keep track of. Recently I wrote a few macros and helper functions that take advantage of varargs and macro token concatenation to cut out some code I found myself repeating often. I haven't "officially" released it yet (still documentation and testing to be done), but here it is for anyone who wants to poke around:
http://pastie.org/8935225
I'll definitely have to look at Steve Donovan's API to see what ideas I can st-- borrow as well. :-)
--
Sent from my Game Boy.