目录路径我需要这段代码转换在Perl到Lua使用Lua中
open(FILE, '/proc/meminfo');
while(<FILE>)
{
if (m/MemTotal/)
{
$mem = $_;
$mem =~ s/.*:(.*)/$1/;
}
elseif (m/MemFree/)
{
$memfree = $_;
$memfree =~ s/.*:(.*)/$1/;
}
}
close(FILE);
到目前为止,我已经写了这个
while assert(io.open("/proc/meminfo", "r")) do
Currentline = string.find(/proc/meminfo, "m/MemTotal")
if Currentline = m/MemTotal then
Mem = Currentline
Mem = string.gsub(Mem, ".*", "(.*)", 1)
elseif m/MemFree then
Memfree = Currentline
Memfree = string.gsub(Memfree, ".*", "(.*)", 1)
end
end
io.close("/proc/meminfo")
现在string.find,当我尝试编译,我得到以下错误关于我的代码
luac: Perl to Lua:122: unexpected symbol near '/'
第二行显然使用STR的目录路径的语法ing.find不像我写的那样。 “但是它怎么样?”是我的问题。
非常感谢你 – OddCore 2010-07-07 10:43:48
很高兴为您提供帮助。如果你打算在Lua进一步编码,我建议你阅读Lua的Programming,它的第一版可以在http://www.lua.org/pil/免费在线获得。 – ponzao 2010-07-07 11:33:48
我拥有由k.Jung和A.Brown撰写的Beggining Lua Programming,这本书是我在教科书中看到的最好的索引。麻烦的是,在我负责将大约300行Perl语言翻译成Lua之前,我从来没有完成过其中的任何一个,所以我正在并行地学习它们。 – OddCore 2010-07-08 07:40:07