[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Locking Table Member Additions
- From: Tim Hill <drtimhill@...>
- Date: Tue, 17 Jun 2014 15:26:58 -0700
On Jun 17, 2014, at 10:04 AM, Leinen, Rick <RLeinen@leviton.com> wrote:
> Thanks for your reply Sean.
>
> Yes, I know Lua typically starts arrays with a 1. Old habits die hard. :-) I put the nil assignment there as a flag. Maybe that's not necessary. I'll explore that.
>
> Yes, creating the table in C is more work. I have a couple of reasons for exploring this option.
> 1) Lua is new to our company. We are hoping that it will allow us to place the functionality of the product in a Lua script rather than hardcoded in C/C++. This will make it much easier to change or add functionality, even in the field. As a result, there may be occasion where our field service engineers may make modifications. Since none of the staff are coding experts, I want to hide as much of the nitty-gritty stuff as possible. That is the reason I would like to lock the members of the table. Less chance for mistakes.
> 2) 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.
>
> I'll have to study your suggestions a bit, as I am fairly new to Lua, especially the C side.
>
> Thanks again,
>
> Rick Leinen
> Engineering Manager, R&D Projects
>
> Lighting and Energy Solutions
>
> T: 503 404-5561 F: 503 404-5661 C: 503 860-6305
>
Couple of things to note. Byte-for-byte, compiler Lua code is very compact. You might find the Lua code to build the table is smaller than the equivalent C code. As others have noted, you might be better served by validating the table when passed to a C function, rather than trying to lock it down proactively (again, probably less code overall to do this).
—Tim