DWScript: how do I get Result after Call
Asked Answered
I

1

6

Alright, I am totally new to DWScript. For now I am fascinated by its abilities, but although I read all the pages in the accompanying wiki and questions/answers here I still cannot find a way to extract the result after a function is called from Delphi like this:

  func := m_dwsExec.info.Func[funcname];
  func.call(params);

and then I'm stuck: exec.result.toString gives me nothing. As long as I see I have no Result in the exec object and that's why when clearing the items from the script stack the result is being removed and lost. Please advice me on what is the proper way to do this simple task?

Invitatory answered 9/1, 2013 at 14:45 Comment(1)
Welcome to Stack Overflow. It's great you found the answer to your question, but please write the answer in the answer section, below.Alphonso
I
7

Edit:

As Eric Grange stated in the comments below the best practice is like this:

  func := m_dwsExec.info.Func[funcname];
  info := func.call(params);
  funcresult := info.ValueAsString; //or Value, ValueAsInteger, etc.

Original answer:

Well I found the answer - the missing result is located in the data property of the returned IInfo object:

  func := m_dwsExec.info.Func[funcname];
  info := func.call(params);
  funcresult := info.data[0]
Invitatory answered 9/1, 2013 at 15:26 Comment(4)
As you may have seen, the real documentation lies in the literally hundreds of unit test cases that Eric has created in the Test folder. It may seem daunting at first, but each case is quite simple and will often show you the way.Andee
For simple types you have Value and ValueAsXxx methods. The Data[] array is for more complex cases or when you want direct access to the variants.Ethridge
Btw, it's also documented in code.google.com/p/dwscript/wiki/FirstSteps, in the "Functions" paragraphEthridge
@EricGrange yes, it's there indeed - my mistakeInvitatory

© 2022 - 2024 — McMap. All rights reserved.