[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Will Lua work in this situation?
- From: Patrick Donnelly <batrick@...>
- Date: Thu, 14 May 2009 04:17:23 -0600
On Thu, May 14, 2009 at 3:29 AM, Lloyd <lloyd@cdactvm.in> wrote:
>
> Hi,
> My application needs a continuously changing policy support. This policy
> will be implemented as Lua script. The policy will be changed only by the "C
> functions" which are called from the Lua script.As an example my initial
> policy may look like this:-
>
> if my_c_function1()==10 then
> print("10 from my_c_function1")
> else
> print("not 10 from my_c_function1")
> end
>
>
> Later I may need to add support for another function "my_c_function2()"
> "without recompiling my original application". So my new policy script would
> look like this:-
>
> if my_c_function1()==10 then
> print("10")
> else
> print("not 10")
> end
>
> if my_c_function2()==10 then
> print("10 from my_c_function2")
> else
> print("not 10 from my_c_function2")
> end
>
> Can I add this kind of functionality using Lua? I read the "C Libraries
> (http://www.lua.org/pil/26.2.html)" section in Lua book. Still I am not
> clear about extending without recompiling the main application code. Some
> hints would be very helpful.
This would actually be fairly simple to accomplish if you were to
compile each policy update as a separate Lua script and execute them
serially (this would not at all be slow). You could create a simple C
function that would iterate over all the scripts (policies) calling
each one. These would of course be saved in a table which you could
then add policies to.
--
-Patrick Donnelly
"Let all men know thee, but no man know thee thoroughly: Men freely
ford that see the shallows."
- Benjamin Franklin