Re: init.e - standard library candidate

new topic     » goto parent     » topic index » view thread      » older message » newer message
ghaberek said...

You've inadvertently solved a quandary that has been plaguing me for years: How do I pass only the name of a routine to an event handler, instead of embedding routine_id() in the function call? I had no idea that initializer values were called inline, which is what seems to make this magic work.

Quite simply...

public procedure SetHandler( atom this, atom id, atom event, sequence handler, integer rid = routine_id(handler) ) 
 
    if length(handler) > 0 and rid = -1 then 
        crash( "Routine %d not found!\n", {handler} ) 
    end if 
 
    -- store handler... 
 
end procedure 
 
-- later... 
 
SetHandler( frame, wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, "MyFrame:OnClick" ) 

Am I wrong, or should this work as I expect?

Yes:

-- foo.ex 
include foo.e 
procedure bar() 
 
end procedure 
foo( "bar" ) 
 
-- foo.e 
 
export procedure foo( sequence name, integer rid = routine_id( name ) ) 
	? rid 
end procedure 

$ eui foo.ex 
0 

Success!

Matt

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

Search



Quick Links

User menu

Not signed in.

Misc Menu