where to register the wml handlers
Moderator: Forum Moderators
where to register the wml handlers
Hi guys,
There is the WML_HANDLER_FUNCTION macro,which handles auto registeration for wml handlers in game_events.cpp. However, I can't find the location to add these handlers.
I debug the code,the dump is as following:
#0 00000000 game_events::command_handlers::add_handler(this=0xb63480, key=@0x22fefc, func=0x59891e <wml_func_remove_shroud>) (C:\wesnoth-1.5.6\src\game_events.cpp:171)
#1 005A25E5 wml_func_register_remove_shroud(this=<value optimized out>) (C:\wesnoth-1.5.6\src\game_events.cpp:433)
#2 005A286E __static_initialization_and_destruction_0(__initialize_p=<value optimized out>, __priority=<value optimized out>) (C:\wesnoth-1.5.6\src\game_events.cpp:433)
#3 005A3387 global constructors keyed to _ZN77_GLOBAL__N_C__wesnoth_1.5.6_src_game_events.cpp_00000000_B9A5325B15manager_runningE() (C:\wesnoth-1.5.6\src\game_events.cpp:3629)
#4 004013E2 __main() (??:??)
#5 0040122A __mingw_CRTStartup() (??:??)
#6 004012B8 WinMainCRTStartup() (??:??)
I can't understand the meaning of "__static_initialization_and_destruction_0".
Who give me the help?
Thanks ahead.
There is the WML_HANDLER_FUNCTION macro,which handles auto registeration for wml handlers in game_events.cpp. However, I can't find the location to add these handlers.
I debug the code,the dump is as following:
#0 00000000 game_events::command_handlers::add_handler(this=0xb63480, key=@0x22fefc, func=0x59891e <wml_func_remove_shroud>) (C:\wesnoth-1.5.6\src\game_events.cpp:171)
#1 005A25E5 wml_func_register_remove_shroud(this=<value optimized out>) (C:\wesnoth-1.5.6\src\game_events.cpp:433)
#2 005A286E __static_initialization_and_destruction_0(__initialize_p=<value optimized out>, __priority=<value optimized out>) (C:\wesnoth-1.5.6\src\game_events.cpp:433)
#3 005A3387 global constructors keyed to _ZN77_GLOBAL__N_C__wesnoth_1.5.6_src_game_events.cpp_00000000_B9A5325B15manager_runningE() (C:\wesnoth-1.5.6\src\game_events.cpp:3629)
#4 004013E2 __main() (??:??)
#5 0040122A __mingw_CRTStartup() (??:??)
#6 004012B8 WinMainCRTStartup() (??:??)
I can't understand the meaning of "__static_initialization_and_destruction_0".
Who give me the help?
Thanks ahead.
Re: where to register the wml handlers
I hope you already got an answer elsewhere, but just in case...
The macro sets an object at namespace scope. As a consequence, this object will be automatically created at the start of the program, since the compiler somehow needs to ensure that the object is valid by the time a function of the file tries to access this object (there is no such functions, but this is irrelevant). In order to so, the compiler creates from thin air a function called __static_init... which is responsible for creating the object. Then the linker ensures this function is executed early by calling it from _main.
So you don't have to do anything: Just use the macro and the created object will ensure it is registered.
The macro sets an object at namespace scope. As a consequence, this object will be automatically created at the start of the program, since the compiler somehow needs to ensure that the object is valid by the time a function of the file tries to access this object (there is no such functions, but this is irrelevant). In order to so, the compiler creates from thin air a function called __static_init... which is responsible for creating the object. Then the linker ensures this function is executed early by calling it from _main.
So you don't have to do anything: Just use the macro and the created object will ensure it is registered.