Re: [Vala] Execute a function by name in Genie



On 3 July 2010 18:50, Andrew <rugby471 gmail com> wrote:
Let's say I have the following code with the pseudo-function 'eval' :

-------
def doSomething(arg1:string)
       print arg1

init
       eval("doSomething('Hello World!')")
-------

How do I do the 'eval' pseudo-function in Genie?

Generally, this is a pretty bad idea - is there really a requirement
for this? If you want to allow access for some sort of scripting,
maybe consider embedding lua or something.

If you really want to do the eval thing, then you would need to:
1) write a parser for the expression strings, possibly by using libvala.
2) generate metadata about your program at compile time, and
distribute this with the app, possibly using gobject-introspection.
3) load the metadata at run time, and compare this with the results of stage 1.
4) run the discovered code.

So basically you are writing a script interpreter, which isn't that trivial...

If you only want to be able to run some specific subset of functions,
then you could manually build a map from function name to function
pointer, but you still need to parse the strings etc.

Hope some of that helps.

Thanks
--
Andrew
_______________________________________________
vala-list mailing list
vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list


-- 
Phil Housley



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