lua-users home
lua-l archive

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


Greetings,

 

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)

 

I’ve stepped through the code and found that the error appears to occur in the following code:

 

   void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {

     void *newblock;

     global_State *g = G(L);

     size_t realosize = (block) ? osize : 0;

     lua_assert((realosize == 0) == (block == NULL));

   #if defined(HARDMEMTESTS)

     if (nsize > realosize && g->gcrunning)

       luaC_fullgc(L, 1);  /* force a GC whenever possible */

   #endif

     newblock = (*g->frealloc)(g->ud, block, osize, nsize);

     if (newblock == NULL && nsize > 0) {

       api_check(L, nsize > realosize,

                    "realloc cannot fail when shrinking a block");

       if (g->gcrunning) {

         luaC_fullgc(L, 1);  /* try to free some memory... */

         newblock = (*g->frealloc)(g->ud, block, osize, nsize);  /* try again */

       }

       if (newblock == NULL)

         luaD_throw(L, LUA_ERRMEM);

     }

     lua_assert((nsize == 0) == (newblock == NULL));

     g->GCdebt = (g->GCdebt + nsize) - realosize;

     return newblock;

   }

 

“newblock” is evidently set to NULL and the code calls luaD_throw() which deals with the error.

 

Anyone have any ideas to help resolve this?

 

Thanks,

 

Rick