1. call_func and routine_id and...
- Posted by C & K L <candk at TICNET.COM> Jan 19, 1999
- 466 views
- Last edited Jan 20, 1999
Howdy! I've got an include file I'm wanting to put some dynamically defined functions in... know what I mean? add_func_name("x") --adds the function named "x" to a list of functions. function x --do something return something end function i = routine_id("x") -- right? All_Functions = append(All_Functions, i) Then later, to call it: call_func(All_Functions[someVariable]) Is this all basically right. Anybody who's an expert can point me to some sample code (Ralf ;) T'anks! ck
2. Re: call_func and routine_id and...
- Posted by "Hawke' (Mike Deland)" <mdeland at GEOCITIES.COM> Jan 20, 1999
- 466 views
>I've got an include file I'm wanting to put some dynamically defined >functions in... know what I mean? >add_func_name("x") --adds the function named "x" to a list of functions. >function x > --do something >return something >end function >i = routine_id("x") -- right? >All_Functions = append(All_Functions, i) >Then later, to call it: >call_func(All_Functions[someVariable]) take a look at EUServer, specifically the parser I built within it. The brunt of the parser is contained in the files: basiccmd.e and cmdlist.e within the euserver zip file... it implements a dynamic function list like you describe. another good example I know of is within win32lib itself for storing the on_this[blah] and on_that[blech] stuff... like on_load[window]=routineid(window_load) and on_mouse[window]=routineid(window_mouse) type of stuff... so, those are two (imo, good) locations to get some pratical, real world, easy to understand examples of the elegance of routineID... enjoy--Hawke'
3. Re: call_func and routine_id and...
- Posted by Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL> Jan 20, 1999
- 458 views
Since, you used my name, I'll show you some example code. It seems, you want to use quoted strings as identifers. Or at least, an identifer of yourself (otherwise, you dont need any mechanism other than routine pointers themselves) Below is a little small library that does this for you. It does two things mainly. You first register your routine and assign an handle. (handle can be something like "my_var" or a integer that has been assigned to a constant, or just any type of arbiturary object) You call the routine with call_routine (handle, arguments). It will always return at least a one element sequence. The first element will be either TRUE or FALSE, as in SUCCES or FAILURE. The second element contains whatever has been returned, *if* it was a function. Otherwise there is no second element. Example: -------- function my_func (integer a, integer b) return "HellO!" end function add_function ("my_func", routine_id ("my_func")) procedure my_proc (integer a, integer b) puts (1, {a,b}) end procedure add_procedure ("my_proc", routine_id ("my_proc")) -- Now both the function and procedure have been registered, you can do this: sequence result result = call_routine ("my_proc", {'a','b'}) -- result is now {TRUE} result = call_routine ("my_func", {'a','b'}) -- result is now {TRUE, "HellO!"} result = call_routine ("my_house", {'a','b'}) -- result is now {FALSE} I dont think this is exactly what you want, however, the code can be a guideline how to set such a thing up. If you explain where you want to use the routine mechanism for, rather than how (give a little more detailed information, what you exactly want), then I can write something more towards your needs. On the other hand, maybe this was just what you wanted. Anyways, good luck, the library follows. (really small anyway) -- rpman.e constant TRUE = 1, FALSE = 0 sequence types, handles, rps global procedure add_function (object handle, integer rp) integer pos pos = find (handle, handles) if pos then types[pos] = TRUE -- It does return something rps[pos] = rp else handles = append(handles, handle) types = append(types, TRUE) rps = append(rps, TRUE) end if end procedure global procedure add_procedure (object handle, integer rp) integer pos pos = find (handle, handles) if pos then types[pos] = FALSE -- It does return something rps[pos] = rp else handles = append(handles, handle) types = append(types, FALSE) rps = append(rps, FALSE) end if end procedure global function call_routine (object handle, sequence arg) integer pos pos = find (handle, handles) if pos then if types[pos] then return {TRUE, call_func (rps[pos], arg) else call_proc (rps[pos], arg) return {TRUE} else return {FALSE} end if end function --- End of it