Re: Substitute for routine_id?

new topic     » goto parent     » topic index » view thread      » older message » newer message
irv said...
? plustwo(6) 
? routine_id("plustwo") 
 
function plustwo(integer x) 
return x+2 
end function 

The first line prints 8, as you would expect the second prints -1, because it can't see forward. As a result, call_back also fails:

This causes much typing and moving functions around into awkward places when using EuGTK.

Is there some way to write a substitute for

call_back(routine_id("foo")) 

that will be able to 'see' forward functions?

Or some way to look thru the registry of function names?

This is still awkward, but call_back() does not require that it be placed after a function has declared. Unlike routine_id(), call_back() doesn't care about scope at all, it'll work as long as it's given a valid routine id, no matter where it is.

So you can do this

procedure some_routine_not_called_until_later() 
call_back(foo_routine_id) 
... 
end procedure 
 
... 
 
function foo() 
... 
end function 
constant foo_routine_id = routine_id("foo") 
 
... 
 
some_routine_not_called_until_later() 

If you need to generate the call_back() at runtime in a spot before the function was declared and routine_id() called, then this won't help you. (There is a routine id table internally, but you have no way to access that. You could just pass in random numbers to call_back() and hope that you get the right function (e.g. call_back(4) ) but that's obviously a bad idea.)

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu