lua-users home
lua-l archive

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

-----Original Message-----
From: [] On Behalf Of Tom N Harris
Sent: Tuesday, June 17, 2014 1:49 PM
Subject: Re: Locking Table Member Additions

On Tuesday, June 17, 2014 05:04:29 PM Leinen, Rick wrote:
> The Kinetis microcontroller I am targeting has 1MB of internal flash 
> and 256KB of internal SRAM.  Neither is a lot, but I have much more 
> flash.  By defining the table in C, I am hoping that I will be using 
> less RAM since the Lua script will be smaller.  This may prove out to 
> be negligible, but that is the thinking at the time.

The Lua runtime will allocate a table from the same memory pool whether the definition is made in a script or by C API calls. What you want to do is create userdata to allow scripts to access the message data in the C structures. You then have control over where that memory is allocated. You also save time by not copying data when dispatching the message.

tom <>

Thanks Tom,

This sound like it may be a better solution.  I looked at userdata, but I got the impression that it allowed Lua to use a C generated types.  It wasn't clear to me if both Lua and C could access the data.

As far as saving memory, I assumed that the same amount of memory would be used whether it was created in C or Lua.  I was trying to keep the size of the Lua script down.  When a script is passed to a Lua state, is the full ASCII text pulled into RAM and then parsed, or does it do it line-by-line?