[Home]

Summary:ASTERISK-24148: Can not use mysql at extensions.lua
Reporter:Yuriy Gorlichenko (ovoshlook)Labels:
Date Opened:2014-07-31 08:19:47Date Closed:2014-08-07 09:54:45
Priority:MajorRegression?
Status:Closed/CompleteComponents:PBX/pbx_lua
Versions:Frequency of
Occurrence
Related
Issues:
is duplicated byASTERISK-23818 PBX_Lua: after asterisk startup module is loaded, but dialplan not available
Environment:Attachments:
Description:Hello. I successfully installed asterisk 12.4.0 with lua and use lua_pbx with my dialplan, but I need to use mysql.

I installed luasql.mysql and without extensions.lua it work fine (woth external scripts)

I tested it with my little script:

{noformat}
function mysqltest()

local driver = require "luasql.mysql"
local env = assert(driver.mysql())
local con = assert(env:connect("mydb", "root", "mypass", "localhost", 3306));
local cur = assert(con:execute("SELECT version()"));

print("<mysql> MYSQL driver version is: "..driver._MYSQLVERSION);
print("<mysql> "..driver._COPYRIGHT);
print("<mysql> "..driver._DESCRIPTION);
print("<mysql> "..driver._VERSION);

cur:close()
con:close()
env:close()
end;

mysqltest()
{noformat}


when I called it as
>lua mysqltest.lua

I see response:

{noformat}
<mysql> MYSQL driver version is: 5.5.37
<mysql> Copyright (C) 2003-2012 Kepler Project
<mysql> LuaSQL is a simple interface from Lua to a DBMS
<mysql> LuaSQL 2.3.0
{noformat}


when I tried require driver from extensions.lua, I see this when reload module pbx_lua.so:


module reload pbx_lua.so

{noformat}
No such module 'pbx_lua.so'
   -- Reloading module 'pbx_lua.so' (Lua PBX Switch)
[Jul 24 11:41:27] ERROR[3512]: pbx_lua.c:1635 load_or_reload_lua_stuff: Error loading extensions.lua:
error loading module 'luasql.mysql' from file '/usr/local/lib/lua/5.1/luasql/mysql.so':
       /usr/local/lib/lua/5.1/luasql/mysql.so: undefined symbol: lua_settop
stack traceback:
       [C]: ?
       [C]: in function 'require'
       [string "extensions.lua"]:1: in main chunk
{noformat}

I uses this issue for fixing problem, but it does not
ASTERISK-17279

So at weekend I deep googled this problem and found some things:

At previous issue (17279) another things I find that I need to load pbx_lua module with global simbols. I found a the old file modules.conf (at asterisk like  1.6) was section [globals] that includes at itself modules that must be loaded with golbal simbols:

lua_pbx.so=yes

So I changed my modules.conf but it no affect. So my Question changed from :

How I must install lua to my server for wotrking with luasql.mysql at extensions.lua?

to:
How to load Asterisk module with global simbols?

I thiks that is write question.
Comments:By: Rusty Newton (rnewton) 2014-08-07 09:49:13.125-0500

Assigning to George for triage. (lua!)

By: Matt Jordan (mjordan) 2014-08-07 09:54:32.930-0500

This should be fixed now by the commit George made last night:

{quote}
------------------------------------------------------------------------
r420146 | gtjoseph | 2014-08-06 11:05:39 -0500 (Wed, 06 Aug 2014) | 30 lines

pbx_lua: fix regression with global sym export and context clash by pbx_config.

ASTERISK-23818 (lua contexts being overwritten by contexts of the same name in
pbx_config) surfaced because pbx_lua, having the AST_MODFLAG_GLOBAL_SYMBOLS
set, was always force loaded before pbx_config.  Since I couldn't find any
reason for pbx_lua to export it's symbols to the rest of Asterisk, I simply
changed the flag to AST_MODFLAG_DEFAULT.  Problem solved.  What I didn't
realize was that the symbols need to be exported not because Asterisk needs
them but because any external Lua modules like luasql.mysql need the base
Lua language APIs exported (ASTERISK-17279).

Back to ASTERISK-23818...  It looks like there's an issue in pbx.c where
context_merge was only merging includes, switches and ignore patterns if
the context was already existing AND has extensions, or if the context was
brand new.  If pbx_lua is loaded before pbx_config, the context will exist
BUT pbx_lua, being implemented as a switch, will never place extensions in
it, just the switch statement.  The result is that when pbx_config loads,
it never merges the switch statement created by pbx_lua into the final
context.

This patch sets pbx_lua's modflag back to AST_MODFLAG_GLOBAL_SYMBOLS and adds
an "else if" in context_merge that catches the case where an existing context
has includes, switchs or ingore patterns but no actual extensions.

ASTERISK-23818 #close
Reported by: Dennis Guse
Reported by: Timo Teräs
Tested by: George Joseph
Review: https://reviewboard.asterisk.org/r/3891/
{quote}

By: Matt Jordan (mjordan) 2014-08-07 09:54:45.863-0500

Closing out as a duplicate of ASTERISK-23818