lua-users home
lua-l archive

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

On Jun 13, 2014, at 11:56 AM, Luiz Henrique de Figueiredo <> wrote:

> Constants and locals have roughly the same performance in the Lua VM:
> both are stored in C arrays. The only difference is that the maximum
> number of locals is much smaller than the maximum number of constants.

Yes, this I do understand. When my switch patch saves out jump tables it actually just saves the constant index and the jump offset for each entry, then when reading in the binary file it uses this information to recreate the actual table structure.

> I've posted a token filter that expanded constants at compile time:

That is a pretty nifty patch, thank you for sharing it... though I do wonder why such a simple patch has not made it into Lua proper? Adding a simple 'const' keyword and storing the value in the _CONSTANTS table could be a nice easy way to add symbolic constants to vanilla Lua, or am I missing something?

The patch I created allows for the recording of the parsed token stream into a token buffer, storage of these token buffers on a separate stack, manipulation of the token buffers (adding and removing tokens) and token stack (adding and removing buffers), playback of token buffers, and a C API to support it all.

Of course this means my patch is quite a bit larger than yours... but then my patch allows for consts, macros (with parameters), and a type of inline function, plus anything anyone else can dream up using the token storage API! :)