I have a couple modules that are just plain CMODs, with no pike stub at all. Is there a way to put a couple of add_string_constant() calls into the PIKE_MODULE_INIT{} section that is generated from a CMOD? I tried just making an INIT{} section in the module outside of the classes, but that didn't work.
Adam
I have a couple modules that are just plain CMODs, with no pike stub at all. Is there a way to put a couple of add_string_constant() calls into the PIKE_MODULE_INIT{} section that is generated from a CMOD? I tried just making an INIT{} section in the module outside of the classes, but that didn't work.
Which version of Pike?
From a somewhat recent precompile.pike:
* AUTOMATIC ALLOCATION AND DEALLOCATION OF CONSTANT STRINGS * You can use the syntax MK_STRING("my string") to refer to * a struct pike_string with the content "my string", or the * syntax MK_STRING_SVALUE("my string") for the same, but a * full svalue. Note that this syntax can not be used in macros.
On Fri, 25 Nov 2005 17:55:16 +0000 (UTC) "Henrik Grubbstr_m (Lysator) @ Pike (-) developers forum" 10353@lyskom.lysator.liu.se wrote:
I have a couple modules that are just plain CMODs, with no pike stub at all. Is there a way to put a couple of add_string_constant() calls into the PIKE_MODULE_INIT{} section that is generated from a CMOD? I tried just making an INIT{} section in the module outside of the classes, but that didn't work.
Which version of Pike?
7.6.50.
From a somewhat recent precompile.pike:
- AUTOMATIC ALLOCATION AND DEALLOCATION OF CONSTANT STRINGS
- You can use the syntax MK_STRING("my string") to refer to
- a struct pike_string with the content "my string", or the
- syntax MK_STRING_SVALUE("my string") for the same, but a
- full svalue. Note that this syntax can not be used in macros.
I'm not quite sure how this works. If I want to set the constant __version to be "1.1", how do I do that?
Adam
On Fri, 25 Nov 2005 17:55:16 +0000 (UTC) "Henrik Grubbstr_m (Lysator) @ Pike (-) developers forum" 10353@lyskom.lysator.liu.se wrote:
I have a couple modules that are just plain CMODs, with no pike stub at all. Is there a way to put a couple of add_string_constant() calls into the PIKE_MODULE_INIT{} section that is generated from a CMOD? I tried just making an INIT{} section in the module outside of the classes, but that didn't work.
From a somewhat recent precompile.pike:
- AUTOMATIC ALLOCATION AND DEALLOCATION OF CONSTANT STRINGS
- You can use the syntax MK_STRING("my string") to refer to
- a struct pike_string with the content "my string", or the
- syntax MK_STRING_SVALUE("my string") for the same, but a
- full svalue. Note that this syntax can not be used in macros.
I'm not quite sure how this works. If I want to set the constant __version to be "1.1", how do I do that?
At the top-level? Something like the following might work:
PIKE_MODULE_INIT { INIT;
#ifdef EITHER add_constant(MK_STRING("__version"), MK_STRING_SVALUE("1.1"), 0); #else /* OR */ add_string_constant("__version", "1.1", 0); #endif }
Adam
PIKE_MODULE_INIT { INIT;
#ifdef EITHER add_constant(MK_STRING("__version"), MK_STRING_SVALUE("1.1"), 0); #else /* OR */ add_string_constant("__version", "1.1", 0); #endif }
Let me just add that the former variant gives larger source code and object code, and slower execution time, and increased dynamic memory usage. MK_STRING{,_SVALUE}, as well as the various MAKE_CONST_STRING macros, are _only_ meaningful in code run more than once.
And besides, even _if_ Pike would re-initialize the module, the extra code generated by MK_STRING also sits in the initialization function, so it too would be executed again. => no profit. You lose.
pike-devel@lists.lysator.liu.se