lua-users home
lua-l archive

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


Lythoner LY wrote:
> Hi All,
> 
> I am working on an interesting industrial automation application where I
> am proposing Lua to our customer as a configuration and scripting language.
> I found Lua in search for better language with small runtime, easy to
> extend feature. I like Lua because it so simple to use, understand, very
> handy and compliments python on many places.
> I need the community help to standardize my configuration stuffs which I
> am writing now.
> 
> We needed to provide a simple shell scripting capability to our user
> where they can read and write data to the device(industrial automation).
> We have the core layers developed in C# and I was able to call C# from
> Lua and Lua from C#. And also I can write & read the data with the
> device. Perfect. I also modified one window based IronPython User
> control to support Lua on .NET. For us, Lua would have a window based
> User control to allow user to read and write data. I did replaces
> "print" function Lua with my C# callable function, hence I could capture
> the "print" function output. For me, it is OK so for.
> 
> Now I needed a help on configuration.
> 
> function DEF_PARAM(v)
> return v
> end
> 
> DeviceParam1= DEF_PARAM
> {
> NAME     = "DeviceParam1",
> TYPE     = INT
> }
> 
> 
> DeviceParam2= DEF_PARAM
> {
> NAME     = "DeviceParam2",
> TYPE     = INT
> }
> 
> 
> DeviceParam3= DEF_PARAM
> {
> NAME     = "DeviceParam3",
> TYPE     = INT
> }
> 
> The above is the configuration I use. Like "DeviceParam1", I have tens
> of thousand configurations parameters. DEF_PARAM is an example function
> which just return the variable as it is. But we do some extra business
> logics inside. I have taken them out in this posting.
> 
> DeviceParam1 is used as a variable(a table instance). I need it like
> that. But I have defined one more property called "NAME" which is
> assigned to "DeviceParam1" string. The same is repeated for all
> variables. Instead I want the string equivalent of variables
> DeviceParam1, DeviceParam2, DeviceParam3 handled internally by Lua and
> assigned to  NAME property.
> 
> Here is example.
> 
> function DEF_PARAM(v)
> -- do something here to set NAME property from v
> -- v["NAME"] = ???? How do I get string equivalent of variable v
> return v
> end
> 
> DeviceParam1= DEF_PARAM
> {
> -- NAME     = "DeviceParam1", -- I have taken off the NAME assignment here
> TYPE     = INT
> }
> 
> DeviceParam2= DEF_PARAM
> {
> TYPE     = INT
> }
> 
> 
> DeviceParam3= DEF_PARAM
> {
> TYPE     = INT
> }
> 
> 
> In shell,
> 
>> print(DeviceParam3.NAME)
> DeviceParam3
> 
>>print (type(DeviceParam3.NAME)
> string
> 
> Regards,
> 
> Krish

if you have a limited number of type, you can define them as global
variable :

INT = "INT"
FLOAT = "FLOAT"

function DEF_PARAM(v)
   -- do something here to set NAME property from v
   -- v["NAME"] = ???? How do I get string equivalent of variable v
   return v
end

Just load this script before your definition file, and TYPE will
automatically contain the text.




-- 
--
Julien Hamaide
Engineering Coach
10Tacle Studios Belgium / Elsewhere Entertainment