Hello,

On 3/24/12 1:25 PM, Alex Balashov wrote:
I am not sure that exporting #defines to third-party language API modules makes 
much sense just because some user thought it would be neat.

The #!... constructs are all intended as preprocessor directives, to make 
easier management of global constant values in the native Kamailio config 
environment and to allow easier management of conditionally-enabled chunks of 
code therein, right?

Conceptually, it does not seem to me that they should have any representation 
outside of that evaluative context.  It would be like making preprocessor macro 
values in C available through the libdl/ELF dynamic shared object interface.  
It doesn't make any sense.  If you really want to export preprocessor 
macro-dependent values, trouble yourself to use an intermediate variable--a 
real variable.

In Kamailio, this would take the form:

#!ifdef MYPROJECT

#!define MYPROJECT_IP 1.2.3.4

# Exportable symbol:

myproject.ip = "MYPROJECT_IP" descr "..."

#!endif

Doesn't that make much more sense, in terms of what these directives were 
really intended for?
yes, the directives were added as switches for part of the config initially, next version added also values for defines. I thought of being able to detect in Lua and do switches there as well based on what was defined in kamailio config.

Your solution is good, exporting them to lua will just save some memory and make config smaller. So it is indeed more an optimization, not at all an implementation of a missing (impossible) feature.

Cheers,
Daniel

--
Alex Balashov - Principal
Evariste Systems LLC
235 E Ponce de Leon Ave
Suite 106
Atlanta, GA 30030
Tel: +1-678-954-0671
Web: http://www.evaristesys.com/, http://www.alexbalashov.com

Daniel-Constantin Mierla<mico...@gmail.com>  wrote:

Hello,

On 3/23/12 2:00 PM, Asgaroth wrote:
I'll check this option out, thanks for the tip Alex.
it is a good way to do, $sel(...) are available in Lua, @... format not,
but they are the same, just different access mechanism.

I guess the other option too, which I have not tried, is to possibly
pass in the values as lua script parameters.
Yes, you can do that. You may need to use 'subst' instead of 'define' in
order to be able to replace the token inside another string.

Exporting defines to Lua could be a good enhancement anyhow, I will
think about and maybe add it in the near future.

Cheers,
Daniel

On 23/03/12 12:12, Alex Balashov wrote:
Have you considered using selectors/cfg_get variables instead?

They are also a common way to store various types of "global"
values/constants, with the difference that they can be accessed at
run time using PV container functions instead of set at preprocessing.

myproject.local_ip = "1.2.3.4" descr "IP address"

$sel(cfg_get.my project.local_ip)
Or SER-style: @cfg_get.my project.local_ip

You can evaluate those in Lua, right?

--
Alex Balashov - Principal
Evariste Systems LLC
235 E Ponce de Leon Ave
Suite 106
Atlanta, GA 30030
Tel: +1-678-954-0671
Web: http://www.evaristesys.com/, http://www.alexbalashov.com

Asgaroth<00asgarot...@gmail.com>   wrote:

Hi All,

I am looking at writing a lua function that would really benefit from
accessing "variables" that I would have defined by using the #!define
statement. Is this at all possible? I've tried looking at the
documentation surrounding lua and kamailio, but I cannot see how I
would
access it. I thought I'd ask the list to see if anyone else may have
attempted this.

for example, I may have

#!define INTERNAL_ADDRESS 1.2.3.4

Which I subsequently use through the the routing script to refer to the
internal address I am listening on. Now I would like to try and access
this "variable" from a lua script. Any pointers/tips/workarounds would
be greatly appreciated.

Thanks

_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users


_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
--
Daniel-Constantin Mierla
Kamailio Advanced Training, April 23-26, 2012, Berlin, Germany
http://www.asipto.com/index.php/kamailio-advanced-training/


_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users

--
Daniel-Constantin Mierla
Kamailio Advanced Training, April 23-26, 2012, Berlin, Germany
http://www.asipto.com/index.php/kamailio-advanced-training/


_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users

Reply via email to