Having problems running scripts and hosting. 
Author Message
 Having problems running scripts and hosting.

I'm writing an object to act as a scripting host and trying to test it
out. Currently I don't have a context (item names) and am running the
scripts in the scripting engine's global context.

 I think I'm successfully hosting and what I'd like to do is initially
use scripts as simple math functions, that do some calculations and
return a value.

Everything looks good until I actually run a script (ParseScriptText).

It seems no matter what kind of script I pass to the engine I get an
error (OnScriptError) that says "Invalid Character".

 My scripts are simple...for example I've tried passing...as a test.

Function Celsius(fDegrees)    
        Celsius = (fDegrees - 32) * 5 / 9
End Function

x = Celsius(31)

I've also tried just passing

        Celsius = (fDegrees - 32) * 5 / 9

 What I don't fully understand is my results. How does the script "return
results" from the call to ParseScriptText.

my call looks like

        HRESULT hr = m_Parser->ParseScriptText(theScript, NULL, NULL,
                NULL, 0, 0, 0L, &pvarResult, NULL);

So If I want to write a simple math function, pass it in theScript
variable and get the results back, what does the script look like?

 All I get are errors from the scripting engine.

 I am telling it to use the VBScript engine when I call CoCreateInstance.

 My only other clue is that I don't fully understand dwFlags and the
difference.

dwFlags
        [in] Flags associated with the scriptlet. Can be a combination of
these values:

SCRIPTTEXT_ISEXPRESSION  If the distinction between a computational
expression and a statement is important but syntactically ambiguous in
the script language, this flag specifies that the scriptlet is to be
interpreted as an expression, rather than as a statement or list of
statements. By default, statements are assumed unless the correct choice
can be determined from the syntax of the scriptlet text.  

SCRIPTTEXT_ISPERSISTENT  Indicates that the code added during this call
should be saved if the scripting engine is saved (for example, through a
call to IPersist*::Save), or if the scripting engine is reset by way of a
transition back to the initialized state.  

SCRIPTTEXT_ISVISIBLE  Indicates that the script text should be visible
(and, therefore, callable by name) as a global method in the name space
of the script.  

 To make this long story short, I think I'm correctly hosting the
scripting engine (I am getting script errors) but I don't know what
"form" a script takes when there is no context. I just want it to return
values right now.

 thanks
mike



Tue, 22 May 2001 03:00:00 GMT  
 Having problems running scripts and hosting.
Hi Michael,

Re: "Illegal character error"

You are passing a _Unicode_ string for the source, right?  ParseScriptText
takes an OLECHAR* for the source code, not a char*.

Re: script engine flags:

You list three of the flags along with a pretty concise description of their
meanings.   What exactly is your question?

Re: how does the script "return results"?

If you are asking the script engine to evaluate an expression then it will
fill in the result in pvarRes.  I'm a little confused about what exactly you
are trying to make the script engine do here.  Can you explain a little
better?

Also, something is wrong with your code -- I note in your code that you say
"&pvarRes" -- if your variable pvarRes is a VARIANT * then you are passing
this wrong -- you are passing a VARIANT * * to a function that expects a
VARIANT *.  On the other hand, if pvarRes is a VARIANT, then you have named
a VARIANT using the naming convention for a VARIANT*.

Let me know if you have any other questions.

Eric


Quote:

>I'm writing an object to act as a scripting host and trying to test it
>out. Currently I don't have a context (item names) and am running the
>scripts in the scripting engine's global context.

> I think I'm successfully hosting and what I'd like to do is initially
>use scripts as simple math functions, that do some calculations and
>return a value.

>Everything looks good until I actually run a script (ParseScriptText).

>It seems no matter what kind of script I pass to the engine I get an
>error (OnScriptError) that says "Invalid Character".

> My scripts are simple...for example I've tried passing...as a test.

>Function Celsius(fDegrees)
> Celsius = (fDegrees - 32) * 5 / 9
>End Function

>x = Celsius(31)

>I've also tried just passing

> Celsius = (fDegrees - 32) * 5 / 9

> What I don't fully understand is my results. How does the script "return
>results" from the call to ParseScriptText.

>my call looks like

> HRESULT hr = m_Parser->ParseScriptText(theScript, NULL, NULL,
> NULL, 0, 0, 0L, &pvarResult, NULL);

>So If I want to write a simple math function, pass it in theScript
>variable and get the results back, what does the script look like?

> All I get are errors from the scripting engine.

> I am telling it to use the vbscript engine when I call CoCreateInstance.

> My only other clue is that I don't fully understand dwFlags and the
>difference.

>dwFlags
> [in] Flags associated with the scriptlet. Can be a combination of
>these values:

>SCRIPTTEXT_ISEXPRESSION  If the distinction between a computational
>expression and a statement is important but syntactically ambiguous in
>the script language, this flag specifies that the scriptlet is to be
>interpreted as an expression, rather than as a statement or list of
>statements. By default, statements are assumed unless the correct choice
>can be determined from the syntax of the scriptlet text.

>SCRIPTTEXT_ISPERSISTENT  Indicates that the code added during this call
>should be saved if the scripting engine is saved (for example, through a
>call to IPersist*::Save), or if the scripting engine is reset by way of a
>transition back to the initialized state.

>SCRIPTTEXT_ISVISIBLE  Indicates that the script text should be visible
>(and, therefore, callable by name) as a global method in the name space
>of the script.

> To make this long story short, I think I'm correctly hosting the
>scripting engine (I am getting script errors) but I don't know what
>"form" a script takes when there is no context. I just want it to return
>values right now.

> thanks
>mike




Tue, 22 May 2001 03:00:00 GMT  
 Having problems running scripts and hosting.

Quote:
>  I'm still a little confused about the results...does pvarReturn get filled
> on the
> call to ParseScriptText or after when I call
> SetScriptState(SCRIPTSTATE_CONNECTED)?

If you call ParseScriptText() with a live (non-NULL) result
parameter it will return the result immediately, even in the
INITIALIZED state. No need to START or CONNECT. This is contrary
to those crufty old spruuids-age docs, which state that nothing
happens until the engine is at least STARTed.

If it makes you feel any better, I consider myself reasonably
sharp and I have a hell of a time with the scripting API docs. I
think "you had to be there" during the evolution of the API in
the Denali/pre-IE3 days in order to grok the true meaning of
what's there, and divine what's not there :-)

  -- Bob



Tue, 22 May 2001 03:00:00 GMT  
 Having problems running scripts and hosting.

Quote:
> Re: "Illegal character error"
e
> You are passing a _Unicode_ string for the source, right?  ParseScriptText
> takes an OLECHAR* for the source code, not a char*.

 Yea I sorta stumbled onto this one myself.

 I'm currently hosting the scripting engine within a COM object and for now am reading
the scripts from disk using ifstream into a char buffer (char str[8192]). Being new
to COM I don't know the best way to get from my char buffer to OLECHAR*.

 I will eventually be pulling the scripts out of the database from within the COM object.

Quote:
> Re: script engine flags:
> You list three of the flags along with a pretty concise description of their
> meanings.   What exactly is your question?

 Well I just didn't understand the descriptions at all but after reading them over 20 times
I think I get it now...and I had mis-read the description for pvarResult.

 I read;
or NULL if the caller expects no result (that is, the
   SCRIPTTEXT_ISEXPRESSION value is set).

 and what is printed at the end is.
   SCRIPTTEXT_ISEXPRESSION value is not set).

 so now I understand.

Quote:
> Re: how does the script "return results"?
> If you are asking the script engine to evaluate an expression then it will
> fill in the result in pvarRes.  I'm a little confused about what exactly you
> are trying to make the script engine do here.  Can you explain a little
> better?

 Well the project has many stages but the first stage is to use the scripting engines
to do some math and that's about it. Later we will expose a large object model but I haven't
gotten to that part yet. I just wanted to make sure I could do the basics first,
which was to to minimal hosting inside a COM object and run the simplest script and
get a result.
 I'm still a little confused about the results...does pvarReturn get filled on the
call to ParseScriptText or after when I call SetScriptState(SCRIPTSTATE_CONNECTED)?

Quote:
> Also, something is wrong with your code -- I note in your code that you say
> "&pvarRes" -- if your variable pvarRes is a VARIANT * then you are passing
> this wrong -- you are passing a VARIANT * * to a function that expects a
> VARIANT *.  On the other hand, if pvarRes is a VARIANT, then you have named
> a VARIANT using the naming convention for a VARIANT*.

 A yes I copied and pasted stuff to post in the middle of making changes.

 In the end I think the first issue is still what's holding me up. I don't understand
how to read a script from disk, from withing a COM object (no mfc) and get the script
into an OLECHAR*

 thanks
mike



Wed, 23 May 2001 03:00:00 GMT  
 Having problems running scripts and hosting.
Dude, I _was_ there, and I am still confused.  :-)  No doubt -- Active
Scripting is a complicated interface.

Eric


Quote:

>>  I'm still a little confused about the results...does pvarReturn get
filled
>> on the
>> call to ParseScriptText or after when I call
>> SetScriptState(SCRIPTSTATE_CONNECTED)?

>If you call ParseScriptText() with a live (non-NULL) result
>parameter it will return the result immediately, even in the
>INITIALIZED state. No need to START or CONNECT. This is contrary
>to those crufty old spruuids-age docs, which state that nothing
>happens until the engine is at least STARTed.

>If it makes you feel any better, I consider myself reasonably
>sharp and I have a hell of a time with the scripting API docs. I
>think "you had to be there" during the evolution of the API in
>the Denali/pre-IE3 days in order to grok the true meaning of
>what's there, and divine what's not there :-)

>  -- Bob



Fri, 25 May 2001 03:00:00 GMT  
 Having problems running scripts and hosting.

Quote:

> Dude, I _was_ there, and I am still confused.  :-)  No doubt -- Active
> Scripting is a complicated interface.

heh heh, yeah... but imagine not having access to the sources
and/or the developers!!! We've been promised a real set of docs
on the Active Scripting interfaces for a while, "most lately
after the PDC". I'm just a-beggin-and-pleadin... :-)

  -- Bob



Fri, 25 May 2001 03:00:00 GMT  
 Having problems running scripts and hosting.
But hey, someone promised to bring up to date and clarify the docs after a PDC!
(What we need? Just IActiveScriptProperty and ITridentEventSink... ;-)
But seriously, I'd appreciate the clear docs on flags, specifically,
SCRIPTPROC_IMPLICIT_PARENTS.

Regards,
-cap.



Dude, I _was_ there, and I am still confused.  :-)  No doubt -- Active
Scripting is a complicated interface.

Eric



Sat, 26 May 2001 03:00:00 GMT  
 Having problems running scripts and hosting.

Quote:

>But hey, someone promised to bring up to date and clarify the docs after a

PDC!

As far as I recall, that someone promised to do this not after but for the
PDC ;-)
There is supposed to be some interesting material on the PDC DVD, but those
of us that didn't attend are sort of out of luck.
Please put this stuff on MSDN or your web site!

Cyril



Sat, 26 May 2001 03:00:00 GMT  
 Having problems running scripts and hosting.
I am having a similar problem with understanding the API.  I cannot seem to
get the VB Script to return a result in the pvarResult pointer.  I have in
my code:

        VARIANT* pVarJan;

I then allocate the VARIANT, and since I don't know how big I might need it
I allocate some memory and cast it as the VARIANT like:

         if (pVarJan == 0)
          pVarJan = (VARIANT*)CoTaskMemAlloc(4096);

         if (pVarJan == 0) // alloc failed
          return E_OUTOFMEMORY;

Then issue the call to the VB Script Engine (dwFlags = 0).

 HRESULT hr = STDCOMCALL(m_pActiveScriptParse, ParseScriptText(
  pstrCode,
  pstrItemName,
  punkContext,
  pstrEndDelimiter,
  dwSourceContextCookie,
  ulStartingLineNumber,
  dwFlags,
  pVarJan,
  pexcepinfo));

I know the script executes (because I get an error when I purposely put in a
syntax error), but I always get back VT_Empty in the VARIANT.  My script
looks like:

    Function Eval()
        Eval = "Hello from Script"
    End Function

    Eval

So how do I get the script engine to give me back the "Hello from Script"
string?  Even if I initialize the pVarJan as a string, it still return
empty.  What should be different?

Jan Wiewiora
Unisys Corporation


Quote:
>Hi Michael,

>Re: "Illegal character error"

>You are passing a _Unicode_ string for the source, right?  ParseScriptText
>takes an OLECHAR* for the source code, not a char*.

>Re: script engine flags:

>You list three of the flags along with a pretty concise description of
their
>meanings.   What exactly is your question?

>Re: how does the script "return results"?

>If you are asking the script engine to evaluate an expression then it will
>fill in the result in pvarRes.  I'm a little confused about what exactly
you
>are trying to make the script engine do here.  Can you explain a little
>better?

>Also, something is wrong with your code -- I note in your code that you say
>"&pvarRes" -- if your variable pvarRes is a VARIANT * then you are passing
>this wrong -- you are passing a VARIANT * * to a function that expects a
>VARIANT *.  On the other hand, if pvarRes is a VARIANT, then you have named
>a VARIANT using the naming convention for a VARIANT*.

>Let me know if you have any other questions.

>Eric



Sat, 26 May 2001 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Having problem running a pgm from inside vbs

2. Windows Scripting Host Run method fails - HELP!

3. Windows Scripting Host Run method fails - HELP!

4. Running Scripting Host Files as Logon Script

5. Having a problem with this script

6. msdn.microsoft.com/scripting site having problems?

7. Research: Windows Script Host or Windows Scripting Host

8. Windows Scripting Host (FSO) / Problems with NT

9. Problems Installing Windows Script 5.0 and Windows Script Host 2.0 Beta on Windows NT 4.0

10. .NET Script Host available from Win32 Scripting!

11. Compiling Scripting Host scripts

12. How to get the login Name of the Remote machine, I am having the host name

 

 
Powered by phpBB® Forum Software