lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Tim Hill once stated:
> 
> On Mar 16, 2014, at 2:39 AM, Rena <hyperhacker@gmail.com> wrote:
> 
> > 
> > 
> > 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
> > 
> 
> Yes that’s what we do .. we adopted the notation used in the Lua reference:
> 
> lua_pushnil(L);				// [-0,+1]=1 Push nil
> lua_pushstring(L, “xxx”);		// [-0,+1]=2 Push string
> … etc

  I tend to use the notation used in Forth [1]:

	lua_pushnil(L);			/* ( -- X )	*/
	lua_pushstring(L,"xxx");	/* ( X -- X s ) */
	/* etc ... */

  The notation is:

	( pre-statement stack -- post-statement stack )

and I find it easier to reason about (it's more visual) than the Lua
notation (more compact).  

  Personally, I don't mind the Lua stack.  Perhaps it comes from spending
quite a few years programming assembly language (lots of stack usage there)
and some time playing around with Forth in college.

  -spc 

[1]	A stack based language that, except for one concept [2], trivially
	easy to implement.

[2]	The Forth word DOES> .  What it does is fairly easy to explain (it
	changes the default behavior of a newly defined word) but how it
	does it is another thing entirely.