Cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic execute

Valued Contributor
Valued Contributor

Hi

 

i want to execute a string with the execute comand but when i just insert one command i get an syntaxerror. The problem is that i dont know which type of commnd is in the string. How can i do this ? Here is a sample to show what i mean :

 

is
do
    execute("is do print \"hallo\";end;"); -- prints hello
    execute("print \"hallo\";"); -- error    <- here i need something to change this
    print execute(":string is do return \"hallo\";end;"); -- prints hello
end;

 

I need this because I have a SocketServer with the following Callback Method and need to execute the SocketMessage

(SocketChannelNo: integer; SocketMessage : string)
is
do
    print "executing: "+SocketMessage;
    execute(SocketMessage);
end;

 

4 REPLIES 4

Re: Dynamic execute

Siemens Phenom Siemens Phenom
Siemens Phenom

I would suggest that the socket never sends a message with "is do end". Then you could always put ":any is do " before the command and " end;" behind the command.

 

Look at this example:

is
do
    local command1: string := "print \"hello\"";
    local command2: string := "return 42";

    execute(to_str(":any is do ", command1, " end;"));
    execute(to_str(":any is do ", command2, " end;"));
end;

 

_________________________________________________________________
Did you like the answer? Then click the Thumbs Up button.
Did the answer solve your problem? Then accept the answer as solution.

Re: Dynamic execute

Valued Contributor
Valued Contributor

the problem is i down know whitch message is without a "is do end". When i get a string to execute like "is do print "hallo";end;" i get a syntaxerror because "is do is do print "hallo";end;end;" doese not work

 

is there a method like isExecutable("")

Re: Dynamic execute

Siemens Phenom Siemens Phenom
Siemens Phenom

This should solve your problem:

  if executeSilent(to_str(":any is do ", command, " end;")) = void then
      execute(command);
  end;
_________________________________________________________________
Did you like the answer? Then click the Thumbs Up button.
Did the answer solve your problem? Then accept the answer as solution.
Highlighted

Re: Dynamic execute

Valued Contributor
Valued Contributor

ok thx think that should work for me Smiley Happy