Author Topic: Q: How to eval a string expression  (Read 5864 times)

shadowbane

  • Community Member
  • Posts: 85
  • Hero Points: 4
Q: How to eval a string expression
« on: October 28, 2006, 05:46:25 PM »
I have a string, say "upcase('hi')" that I want to execute (but it does not contain a _command):
Code: [Select]
_str result = some_way_to_execute( string );
so now result should be "HI".

upcase is not a command, so this is out:
Code: [Select]
execute( string )

execute cant take an expression so this is out:
Code: [Select]
execute( '_param1 = ' :+ string );
result = _param1;

Seems like such a simple concept... Any other ideas?

--Tyler

Graeme

  • Senior Community Member
  • Posts: 2793
  • Hero Points: 347
Re: Q: How to eval a string expression
« Reply #1 on: October 31, 2006, 12:05:45 AM »

Have a look at the "names table functions" listed in the "macro functions by category" topic.  Especially see call_index.  Coincidentally it has an example using upcase.  I haven't tried it but the example suggests that even static non-command functions such as upcase_filter are in the names table and can be called through call_index.

If that doesn't work and you're extra keen, you could generate a "source module" on the fly that contained a command that called your function - then use "load" to load the newly generated module and call the command instead of the function.  Looks like call_index should work though.

Graeme