lua-users home
lua-l archive

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

OK, here's my first contribution to a porting guide.


When porting to a limited resource environment, such as an embedded hardware platform, here’s something to watch out for.


The lexical parsing in the Lua core needs a sizable chunk of stack space for such language elements as function definitions. I’ve found that in this case, the function chunk, which presumably is responsible for parsing a chunk of Lua code, winds up calling the function body that allocates the largish structure FuncState on the stack. This function in turn calls chunk again, so if there’s a nested function definition (admittedly pretty complex Lua code), you’ll need another chunk of stack (pardon the pun). I bumped our shell task’s stack size from 4K to 8K to surmount this issue. (FuncState, on my platform, is 0x5D8 bytes in size.)


I know this isn’t relevant if you’ve removed the parsing and are just running compiled code through the Lua VM, but I’m not far enough along to know what stack space requirements the VM has. (BTW, if you’ve done this, please pass along any pointers that might help.)