1

在 Freeswitch 中,传递给 lua 脚本的参数是用空格分隔的(参见http://wiki.freeswitch.org/wiki/Mod_lua#Passing_Arguments)。

我已经确定您可以将参数用单引号括起来,然后忽略空格,但我无法弄清楚如何转义单引号。

应该如何将带空格的参数传递给 Lua?

要重现问题:

示例 Lua 脚本:

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");

这工作正常:

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 *******************

但是我将如何发送参数值“three's a crowd”?

我试过 \', '', ''' 和 " and \" 但这些都不起作用。

4

2 回答 2

1

我试过这个例子,可以逃脱'罚款。这是在最新的 GIT 上完成的吗?

lua q.lua one two 'three\'s a crowd'  four
2012-06-24 13:52:55.376758 [INFO] switch_cpp.cpp:1227 *******************
2012-06-24 13:52:55.376758 [INFO] switch_cpp.cpp:1227 one
2012-06-24 13:52:55.376758 [INFO] switch_cpp.cpp:1227 two
2012-06-24 13:52:55.376758 [INFO] switch_cpp.cpp:1227 three's a crowd
2012-06-24 13:52:55.376758 [INFO] switch_cpp.cpp:1227 four
2012-06-24 13:52:55.376758 [INFO] switch_cpp.cpp:1227 *******************
于 2012-06-24T21:00:48.267 回答
1

我查看了 FreeSWITCH 代码,看起来没有办法逃脱单引号:

这里 mod_lua 调用 switch_separate_string() https://github.com/FreeSWITCH/FreeSWITCH/blob/ee8c9e869ba0da3d4f620769c1e241be71d99e6f/src/mod/languages/mod_lua/mod_lua.cpp#L156

这里 switch_separate_string 调用了separate_string_blank_delim(),它只捕获一个单引号作为参数分隔符: https ://github.com/FreeSWITCH/FreeSWITCH/blob/ee8c9e869ba0da3d4f620769c1e241be71d99e6f/src/switch_utils.c#L2062

于 2012-06-24T11:35:23.287 回答