lua-users home
lua-l archive

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


On Tuesday, June 17, 2014 05:29:14 PM Sean Conner wrote:
>   It's a bit involved, as you need to handle both __index and __newindex in
> C.  You can see an example here:

In this instance, I don't think the table necessarily needs to be exposed as a 
table. A simple functional interface would suffice and be less confusing with 
regards to what parameters are allowed.

    messagePayload:setRelativeLevel(false)
    print( messagePayload:Priority() )
    messagePayload:addDimmer {dim=1, lev=128}

On the other hand, a table-like interface uses less Lua memory. Each function 
in a metatable is a name, closure, and hash table entry. Using the userdata as 
a table only creates two closures and the names, while pushing the time and 
memory onto the C side.

That said, it'll take a very large script to put a dent into 256M. What I said 
about defaults allows you to save a few bytes by not needing to type every 
field name and value. But Lua's string interning, efficient storage of 
numbers, and constants in the prototype do most of the work of keeping memory 
usage reasonable.

Of course the mantra we all must remember is "no premature optimization". This 
applies to space as well as time.

-- 
tom <telliamed@whoopdedo.org>