lua-users home
lua-l archive

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


Am 09.05.2014 02:50 schröbte Leinen, Rick:
Greetings,

Hi!


While I have some experience writing lua scripts, I am new to implementing lua on a hardware platform.  I am trying to implement lua on a Freescale Tower with a Kinetis K65 microcontroller.  It has 2 MB of flash and 256 KB of SRAM on board.  I have successfully built a project using IAR's ARM IDE using one of the Tower's simple demo projects as a launching point.

From main(), the project successfully runs the following line of code:

    lua_State *L = luaL_newstate();

Next, the code attempts to open the lua libraries with this line of code:

    luaL_openlibs(L);

It makes as far as the math library when the following is sent out the serial port from lua:

     PANIC: unprotected error in call to Lua API (math)

Anyone have any ideas to help resolve this?


As Rena said, probably a memory allocation issue (although 256K should be plenty). If you have a look at the source of `lua.c`, you will see that the first thing after `luaL_newstate` is a call to `lua_pcall` to avoid such unprotected errors in case of allocation failures. This should at least give you a more useful error message.

If this really is a memory problem, you might also want to have a look at elua[1] which includes a patch[2] to store module tables readonly in ROM instead of RAM to save memory. Elua has a port[3] for Kinetis which you could use as a starting point (Elua is Lua 5.1, though) ...

Thanks,

Rick


Philipp

  [1]: http://www.eluaproject.net/
  [2]: http://www.eluaproject.net/doc/v0.9/en_arch_ltr.html
  [3]: http://wiki.eluaproject.net/Boards#ARM_Cortex-M4