In Freeswitch arguments passed to lua scripts are space delimited (see http://wiki.freeswitch.org/wiki/Mod_lua#Passing_Arguments ).
I've worked out that you can wrap the argument in single quotes, and this then ignores the space but I can't then work out how to escape single quotes.
How should arguments with spaces be passed to Lua?
To recreate the problem:
Example Lua script:
argumentOne=argv[1];
argumentTwo=argv[2];
argumentThree=argv[3];
argumentFour=argv[4];
freeswitch.consoleLog("info", "*******************\n");
freeswitch.consoleLog("info", argumentOne);
freeswitch.consoleLog("info", "\n");
freeswitch.consoleLog("info", argumentTwo);
freeswitch.consoleLog("info", "\n");
freeswitch.consoleLog("info", argumentThree);
freeswitch.consoleLog("info", "\n");
freeswitch.consoleLog("info", argumentFour);
freeswitch.consoleLog("info", "\n");
freeswitch.consoleLog("info", "*******************\n");
This works fine:
freeswitch@internal> luarun luaargumenttest.lua one two 'thr ee' four
+OK
freeswitch@internal> 2012-06-24 11:56:55.873757 [INFO] switch_cpp.cpp:1197 *******************
2012-06-24 11:56:55.873757 [INFO] switch_cpp.cpp:1197 one2012-06-24 11:56:55.873757 [INFO] switch_cpp.cpp:1197
2012-06-24 11:56:55.873757 [INFO] switch_cpp.cpp:1197 two2012-06-24 11:56:55.873757 [INFO] switch_cpp.cpp:1197
2012-06-24 11:56:55.873757 [INFO] switch_cpp.cpp:1197 thr ee2012-06-24 11:56:55.873757 [INFO] switch_cpp.cpp:1197
2012-06-24 11:56:55.873757 [INFO] switch_cpp.cpp:1197 four2012-06-24 11:56:55.873757 [INFO] switch_cpp.cpp:1197
2012-06-24 11:56:55.873757 [INFO] switch_cpp.cpp:1197 *******************
But how would I send in the argument value "three's a crowd"?
I've tried \', '', ''' and also " and \" but non of these work.
I looked through the FreeSWITCH code, and it looks like there's no way to escape a single quote:
here mod_lua calls switch_separate_string() https://github.com/FreeSWITCH/FreeSWITCH/blob/ee8c9e869ba0da3d4f620769c1e241be71d99e6f/src/mod/languages/mod_lua/mod_lua.cpp#L156
here switch_separate_string calls separate_string_blank_delim(), and it only catches a single quote as an argument delimiter: https://github.com/FreeSWITCH/FreeSWITCH/blob/ee8c9e869ba0da3d4f620769c1e241be71d99e6f/src/switch_utils.c#L2062