我目前正在嵌入Lua并将其用作一个美化的智能配置文件.但是,我认为我缺少一些东西,因为人们对Lua的使用赞不绝口.
例如,我可以通过显示这个示例轻松解释为什么你可以使用shell脚本而不是C(诚然,boost regexp是过度杀伤):
#include <dirent.h>
#include <stdio.h>
#include <boost/regex.hpp>
int main(int argc, char * argv[]) {
DIR *d;
struct dirent *dir;
boost::regex re(".*\\.cpp$");
if (argc==2) d = opendir(argv[1]); else d = opendir(".");
if (d) {
while ((dir = readdir(d)) != NULL) {
if (boost::regex_match(dir->d_name, re)) printf("%s\n", dir->d_name);
}
closedir(d);
}
return(0);
Run Code Online (Sandbox Code Playgroud)
并将其与:
for foo in *.cpp; do echo $foo; done;
Run Code Online (Sandbox Code Playgroud)
你能在Lua中给出任何可以让我"点击"的例子吗?
编辑:也许我的问题是我不知道Lua还不能流利地使用它,因为我发现编写C代码更容易.
EDIT2:
一个例子是C++和Lua中的玩具阶乘程序:
#include <iostream>
int fact (int n){
if (n==0) return 1; else
return (n*fact(n-1));
}
int main …Run Code Online (Sandbox Code Playgroud) 我在man cat(GNU/Linux)中遇到过这个问题.
手册只是说-u (ignored)没有解释原因.
出于好奇,我在谷歌搜索,但似乎没有人问过这个.
然后我看着其他实现的cat.
我注意到Apple的cat也实现了这个选项(参见cat.c).在它的源代码中说
...
case 'u':
setbuf(stdout, NULL);
break;
...
Run Code Online (Sandbox Code Playgroud)
我想这个选项意味着'无缓冲'.这个选项的使用是什么?它为什么存在,为什么被忽略?我认为必须有一些原因.