www.digitalmars.com         C & C++   DMDScript  

DMDScript - eval once again (calling dmdscript global function directly)

reply bobef <bobef_member pathlink.com> writes:
Please consider this code:

Program program = new Program;
RegisterDScriptTypes(program);
program.compile("test", "var d=new String('bobef');", null);
Value ret=*new Value;
Value[] args;
args.length=1;
args[0]=*new Value;
args[0].putVstring("Main(d);");
Dglobal_eval(null,program.callcontext,null,&ret,args);


//end

RegisterDScriptTypes() registers global function Main which displays a message
box. Executing the code above produces a message box saying "undefined" (main
works ok - tested). So it is clear to me that the call to eval() doesn't know
about 'var d...'. And I am not passing any objets to it. I tried with
program.callcontext.global - it does the same. What I need to do to make it
working?
Jun 22 2005
parent reply bobef <bobef lessequal.com> writes:
After two days experimenting I was able to answer myself...

bobef wrote:
 Please consider this code:
 
 Program program = new Program;
 RegisterDScriptTypes(program);
 program.compile("test", "var d=new String('bobef');", null);
 Value ret=*new Value;
 Value[] args;
 args.length=1;
 args[0]=*new Value;
 args[0].putVstring("Main(d);");
 Dglobal_eval(null,program.callcontext,null,&ret,args);
 
 
 //end
 
 RegisterDScriptTypes() registers global function Main which displays a message
 box. Executing the code above produces a message box saying "undefined" (main
 works ok - tested). So it is clear to me that the call to eval() doesn't know
 about 'var d...'. And I am not passing any objets to it. I tried with
 program.callcontext.global - it does the same. What I need to do to make it
 working?
 
 

Jun 24 2005
parent reply "Regan Heath" <regan netwin.co.nz> writes:
Please post the answer. You never know who will find this post in the  
future and thank you for it (even if you never hear about it).

Regan

On Fri, 24 Jun 2005 14:31:50 +0300, bobef <bobef lessequal.com> wrote:
 After two days experimenting I was able to answer myself...

 bobef wrote:
 Please consider this code:
  Program program = new Program;
 RegisterDScriptTypes(program);
 program.compile("test", "var d=new String('bobef');", null);
 Value ret=*new Value;
 Value[] args;
 args.length=1;
 args[0]=*new Value;
 args[0].putVstring("Main(d);");
 Dglobal_eval(null,program.callcontext,null,&ret,args);
   //end
  RegisterDScriptTypes() registers global function Main which displays a  
 message
 box. Executing the code above produces a message box saying "undefined"  
 (main
 works ok - tested). So it is clear to me that the call to eval()  
 doesn't know
 about 'var d...'. And I am not passing any objets to it. I tried with
 program.callcontext.global - it does the same. What I need to do to  
 make it
 working?


Jun 24 2005
parent reply bobef <bobef lessequal.com> writes:
Yes you are right. I didn't post it because my solution is incomplete 
and inexact but perfect for my case. But I should have posted it anyway.
What I needed is the following thing. I extend the script as described 
in the dmdscript page and execute it. At some point I need to call a 
script callback function. So I do it trough eval(). It is perfect 
because I don't need to check if function exists or something else. So 
what I do is compile and execute as usual and at some point do this to 
call eval():

Value ret=*new Value;
Value[] args;
args.length=1;
args[0]=*new Value;
args[0].putVstring("something();");
Dglobal_eval(null,program.callcontext,program.callcontext.global,&ret,args);

In fact I don't pass program.callcontext.global but instead save the 
othis argument in one of my custom global functions. But I checkeed 
othis.toString() and it says Global something so I guess it is the same...
The important thing I found is that you can't call dglobal_eval before 
the program.execute() call, because it do some initialization there. Not 
all the initialization is done in program.compile(). I compared the 
source of dglobal_eval() and program.compile/execute and they do the 
same. I didn't need to go there but if you don't want to call execute I 
guess you should make your own function with the stuff from 
program.compile except the actual execution (which is ir.call or 
something like that if I understood correctly)...
So this is what I learned. Hopefuly it will be useful.

Regan Heath wrote:
 Please post the answer. You never know who will find this post in the  
 future and thank you for it (even if you never hear about it).
 
 Regan
 

Jun 24 2005
parent reply bobef <bobef lessequal.com> writes:
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Here is one more thing. There was a site called 'making dmd script suit 
your needs' which is no more. I was able to pull out this examle out of 
google's cache. It is exapmle of interaction between D and DMDScript. 
There is also slightly modified version of this example at walnut 
project's svn on dsource. I attach them both here.
Jun 24 2005
parent reply Carlos Santander <csantander619 gmail.com> writes:
bobef escribió:
 Here is one more thing. There was a site called 'making dmd script suit 
 your needs' which is no more. I was able to pull out this examle out of 
 google's cache. It is exapmle of interaction between D and DMDScript. 
 There is also slightly modified version of this example at walnut 
 project's svn on dsource. I attach them both here.
 

Yeah, the site was mine. I think my uni's server is down. I don't think it's worthy to have it any longer because I think Walnut is more complete. BTW, Walnut is kinda on hold now because I'm busy. If you (bobef) want to help a bit with it, it'd be truly appreciated. -- Carlos Santander Bernal
Jun 25 2005
parent reply bobef <bobef lessequal.com> writes:
Carlos Santander wrote:

 BTW, Walnut is kinda on hold now because I'm busy. If you (bobef) want 
 to help a bit with it, it'd be truly appreciated.
 

Well, sorry, I don't have any interest in Walnut because I think is too general and I don't think so 'wide' scripting capabilities are in any use because if you need to create full application you'd better use D. Don't get me wrong and please no offense because often my words sound offensive. Walnut is nice project but not in my sphere of interests. Anyway I would support and help a project documenting the DMDScript extending/integration. In fact I am planning such project. After I finish my work with DMD (integration to akIDE, which I am currently working on) and respectively gather some more knowledge about it probably I will try to document it. P.S. recently i amused myself by playing witg d/opengl/physics so this is kind of offtopic but I'm thinking about something like dmdscriptable physical simulation enviroment...
Jun 26 2005
parent Carlos Santander <csantander619 gmail.com> writes:
bobef escribió:
 
 Well, sorry, I don't have any interest in Walnut because I think is too 
 general and I don't think so 'wide' scripting capabilities are in any 
 use because if you need to create full application you'd better use D. 
 Don't get me wrong and please no offense because often my words sound 
 offensive. Walnut is nice project but not in my sphere of interests.
 

You don't need to worry. I was just looking for more hands. It's always worth a try. -- Carlos Santander Bernal
Jun 26 2005