YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

How to implement eval
takekun2
#1 Posted : Friday, April 29, 2011 3:50:52 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 1/5/2011(UTC)
Posts: 5
Location: Tokyo

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Hi,


local a = 10
eval("a = 20")
print(a)


I would like to have 20 as the result of the print above.
How can I write such eval function?

I know how to retrieve local variables through series of sq_getlocal,
but don't know how to let sq_compiler know the current environment...
fagiano
#2 Posted : Friday, April 29, 2011 1:14:39 PM(UTC)
Rank: Advanced Member

Groups: Registered, Administrators
Joined: 6/11/2005(UTC)
Posts: 825

Thanks: 0 times
Was thanked: 36 time(s) in 29 post(s)
Here's how

You can't exactlty do what you want but you can compile a string into a function
then retrive returnvalue or pass parameters to it.
Code:


local compiledscript = compilestring("return 20");

local result = compiledscript();
print("result = " + result + "\n");

local compiledscript2 = compilestring("print(\"param0 = \" + vargv[0]);");
compiledscript2("I'm a prameter");



ciao
Alberto
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.056 seconds.