[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua as Configuration Conditional Statement inside table definition
- From: Nilson <nilson.brazil@...>
- Date: Wed, 10 Nov 2010 16:23:46 -0200
On Wed, Nov 10, 2010 at 5:45 AM, Gopalakrishnan Subramani
<gopalakrishnan.subramani@gmail.com> wrote:
> Hello All,
>
> We are trying to define the configuration for Industrial Automation Devices.
>
> As part of that, we have many complication in using Lua. We have tried Lua
> for this purpose and we could not proceed and we went with XML files for
> configuration. When we define the configuration in XML, we have dificulty in
> condition checking. Hence we write some code in C# to eliminate certain
> portion of code in XML.
>
> Due to this limitation, we want to use Lua for configuration as well as for
> scripting the device functionality.
>
> Here I am start with simple example of definition the enumeration.
>
> Enum1 = ENUMERATION {
> {1, "Forward"},
> {2, "Backword"},
>
> if BIDIERCTIONAL_SUPPORTED then
> {3, "BiDirectional"},
>
> {4, "None" }
> }
>
> If you see, the "Bidirectioanl" is added only if it is enabled. I don't
> think, Lua support statements within the table definition.
>
> Can you help me different possibilities in Lua to resolve this issue?
>
> I have dozens of other issues, I will post them via separate mail.
>
> Regards,
>
> Gopalakrishnan Subramani
>
Would you like to try this?
function conditional(test)
function add(item) return item end
function discard() return nil end
if test then return add end
return discard
end
function ENUMERATION(tab) return tab end
enum1 = ENUMERATION {
{1,'a'},
{2,'b'},
conditional(false) {3,'c'},
conditional(true){4,'d'},
}
for k,v in pairs(enum1) do
print(k,v[1],v[2])
end
--
Nilson