使用gel脚本作为lua脚本

我有以下将字符串分隔为适当单词的lua脚本:

names = "aa bb cc dd"
words = {}
for word in names:gmatch("%w+") do table.insert(words, word) end
for k,v in pairs(words) do print(k,v) end

我使用一个名为Graphite的程序,它是一个用于计算机图形和更多的平台。在它的readme中写道:

你可以编写一个LUA脚本并在Graphite中运行它。只需使用GEL加载 脚本-》执行文件。

由于我对LUA的经验非常少,对GEL一无所知,我在运行脚本时遇到了麻烦。经过一些谷歌搜索,我找到了这个:http://gema.sourceforge.net/new/gel.shtml#3_1,但是我仍然不清楚gel和lua之间的关系。在这个网站上,它被描述为:用于Gema的Lua绑定,这是一个通用的文本处理工具。

例如,上面的脚本在lua解释器中的功能正常。另一方面,当我尝试将其作为.gel脚本执行(因为上述软件需要.gel脚本)时,它会返回语法错误。

有什么办法可以让它运行为.gel脚本吗?还是任何其他可能有用的评论?

点赞
用户1190388
用户1190388

如果你仔细阅读文档,你会注意到:

  • 使用新语法 "![" "!]" 来嵌入 lua 函数到 gema 文件中。

他们也提供了一个示例:

![
function inflog(x)
  if x>0 then return math.log(x)
  else return "-infty"
  end
end
!]

<N>=@lua{return inflog($0)}

按照同样的示例,以下代码应该可以工作:

![
function split(names)
    words = {}
    for word in names:gmatch("%w+") do table.insert(words, word) end
    for k, v in ipairs(words) do print(k, v) end
    return words
end
!]

<N>=@lua{return split($0)}
2018-01-07 18:35:17