1. Substitute for routine_id?
- Posted by irv Sep 20, 2010
- 1306 views
? 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?
2. Re: Substitute for routine_id?
- Posted by jimcbrown (admin) Sep 20, 2010
- 1316 views
? 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.)
3. Re: Substitute for routine_id?
- Posted by irv Sep 20, 2010
- 1265 views
When connecting a call_back to a control - say, a button, a valid pointer to the call_back must be available at that time. It's stored in the control structure itself. Naturally, it's easier and neater if you do that connecting at the same time (and place) that you create the control. All other properties of a control can be set at that point without difficulty.
Also, it gets real tedious to have to type "call_back(routine_id("xxx"))" over and over, when something like: connect("OKButton", "clicked", "MyFunction") would be so much nicer.
Having the connect function look up the pointer (handle) to "OKButton" by name is easy, but getting a pointer to "MyFunction" seems impossible.
4. Re: Substitute for routine_id?
- Posted by jimcbrown (admin) Sep 20, 2010
- 1346 views
When connecting a call_back to a control - say, a button, a valid pointer to the call_back must be available at that time. It's stored in the control structure itself. Naturally, it's easier and neater if you do that connecting at the same time (and place) that you create the control. All other properties of a control can be set at that point without difficulty.
Also, it gets real tedious to have to type "call_back(routine_id("xxx"))" over and over, when something like: connect("OKButton", "clicked", "MyFunction") would be so much nicer.
Having the connect function look up the pointer (handle) to "OKButton" by name is easy, but getting a pointer to "MyFunction" seems impossible.
I think the correct place to change this behavior would be around line 1184 of source/emit.e - that's where the information that tells RoutineId() to stop looking is emitted.
What needs to be done is simple - keep track of every opROUTINE_ID that is emitted, then after the last line of the last file has been processed, go back to these opROUTINE_IDs and replace that information so it points to the end of the code (in the main/file-level scope of the last file) instead.
5. Re: Substitute for routine_id?
- Posted by irv Sep 20, 2010
- 1345 views
Well, changing the source is completely beyond me - so I guess the question to ask is: should routine_id enjoy the same scope rules as a regular function call?
Second question- is it important enough that someone who can mess with the source should take time to do it?
6. Re: Substitute for routine_id?
- Posted by mattlewis (admin) Sep 21, 2010
- 1289 views
Well, changing the source is completely beyond me - so I guess the question to ask is: should routine_id enjoy the same scope rules as a regular function call?
Second question- is it important enough that someone who can mess with the source should take time to do it?
I sort of thought we'd already done this. There's a bit more to it than simply emit.e. The back end needs fixing in be_symtab.c and be_runtime.c and execute.e. And the translator should be updated as well.
Matt