[Home]

Summary:ASTERISK-23844: Load of pbx_lua fails on sample extensions.lua with Lua 5.2 or greater due to addition of goto statement
Reporter:Rusty Newton (rnewton)Labels:
Date Opened:2014-06-09 17:23:28Date Closed:2014-06-19 11:07:44
Priority:TrivialRegression?
Status:Closed/CompleteComponents:Documentation PBX/pbx_lua
Versions:SVN 1.8.28.2 11.10.2 12.3.0 Frequency of
Occurrence
Related
Issues:
Environment:Attachments:
Description:{noformat}
*CLI> module load pbx_lua.so
Unable to load module pbx_lua.so
Command 'module load pbx_lua.so' failed.
[Jun  9 17:17:07] ERROR[19906]: pbx_lua.c:1635 load_or_reload_lua_stuff: Error loading extensions.lua: [string "extensions.lua"]:147: <name> expected near 'goto'
{noformat}

and the line:

{noformat}
               ["1000"] = function()
                       app.goto("demo", "s", 1)
               end;
{noformat}
Comments:By: Rusty Newton (rnewton) 2014-06-16 15:38:55.117-0500

[~gtj] said he could take a look into this.

By: George Joseph (gjoseph) 2014-06-17 12:48:23.245-0500

The problem stems from the use of 'app.goto' which is meant to run the Asterisk goto application.  This works in Lua < 5.2 because there was no goto stament in Lua <5.2 but Lua 5.2 added the Lua goto statement so now the Lua interpreter is seeing an unquoted reference to goto and trying to parse it as an Lua statement.  The same issue would happen for any Asterisk application that has the same name as an Lua reserved word.  There's no code fix for this...it's just how the Lua interpreter works (and rightly so, I believe).

Fortunately, there's a way around it by using a different syntax in the *.lua files.  
Instead of...
  app.goto("local_default",1180,1)

you could use...
  app.Goto("local_default",1180,1)
  app.GOTO("local_default",1180,1)
The capitalization makes Lua not recognize it as a reserved word

or more correctly...
  app['goto']("local_default",1180,1)

The alternate syntaxes are backwards compatible and work for all applications.

So my suggestion would be to change the sample config file to use the app['appname'] syntax and update the wiki pages as well.

I can update the sample ( 1.8, 11, 12, trunk) but I don't think I can update the wiki page.




By: George Joseph (gjoseph) 2014-06-17 12:49:59.904-0500

Rusty, Let me know how you'd like to proceed.


By: Rusty Newton (rnewton) 2014-06-18 08:23:53.873-0500

You make the call on this one. I'm just reporting the issue. :) You could ask for more opinion in #asterisk-dev or on the dev list if you feel you need it.

{quote}
So my suggestion would be to change the sample config file to use the app['appname'] syntax and update the wiki pages as well.
{quote}

This sounds appropriate to me after a little Googling, but I don't have any experience with Lua, so again I defer to those with more experience.

{quote}
I can update the sample ( 1.8, 11, 12, trunk) but I don't think I can update the wiki page.
{quote}

You should have wiki edit permissions now, as a bug marshal and Asterisk developer.

Thanks!

By: George Joseph (gjoseph) 2014-06-18 08:26:52.097-0500

Cool.  I've got a patch up on reviewboard now with the wording.   When it gets approved, I'll update the wiki.


By: Rusty Newton (rnewton) 2014-06-18 08:28:16.659-0500

Thanks!  I also updated the summary of this issue to more accurately reflect what you discovered the issue to be.