Pass any function to the parse_function() command, and it will run it with the integer parameters you provide. You must make sure the function returns a value, even if you don't need a value returned from it. Just end it with
endfunction 1. This could be useful for scripting, although I'm not sure how fast it would be, but I plan on using it for a gui system, to check if a gui asset should be active, what action it should perform, etc.
func$ = "add_values(1,1,2)"
print parse_function( func$ )
wait key
end
function add_values( a,b,c )
d = a + b + c
endfunction d
function parse_function( func$ )
dim par$( 10 )
split string func$,"( ,)"
for i = 1 to 20
n$ = get split word$( i )
if n$ <> ""
inc count
par$( count ) = n$
endif
next i
pointer = get ptr to function( par$( 1 ) )
if pointer > 0
count = count - 1
if count = 1
returnvar = call function ptr( pointer,int( val( par$(2) ) ) )
endif
if count = 2
returnvar = call function ptr( pointer, int(val( par$(2) ) ), int(val( par$(3) ) ) )
endif
if count = 3
returnvar = call function ptr( pointer, int( val( par$( 2 ) ) ), int( val( par$( 3 ) ) ), int( val( par$( 4 ) ) ) )
endif
endif
endfunction returnvar