Lua在哪些长尾词场景下比CC++更适用?

2026-04-01 19:031阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计500个文字,预计阅读时间需要2分钟。

Lua在哪些长尾词场景下比C/C++更适用?

我在深入集成Lua并用作一个炫酷的智能配置文件。但我觉得我失去了一些东西,因为人们对Lua的使用感到惊讶。例如,我可以很轻松地解释为什么你可以使用shell脚本而不是C来显示这

我正在嵌入Lua并将其用作一个荣耀的智能配置文件.但是,我觉得我失去了一些东西,因为人们对于Lua的使用感到吃惊.

例如,我可以很容易地解释为什么你可以使用shell脚本而不是C来显示这个例子(诚然,boost regexp是overkill):

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

并将其与:

for foo in *.cpp; do echo $foo; done;

有没有什么例子,你可以给在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 (){ int input; using namespace std; cout << "Enter a number: " ; cin >> input; cout << "factorial: " << fact(input) << endl; return 0; }

LUA:

function fact (n) if n==0 then return 1 else return n * (fact(n-1)) end end print ("enter a number") a = io.read("*number") print ("Factorial: ",fact(a))

在这里,程序看起来是一样的,但是在include,namespace和main()声明中可以清除一些.也删除变量声明和强类型.

现在有人说这是加大一个更大的计划的优势,还是有更多的呢?这与bash示例的方式不同.

Lua在哪些长尾词场景下比C/C++更适用?

使用Lua等脚本语言具有许多其他优点.

Lua对C的几个优点:

由于高层次的性质,开发时间往往较短,如您的例子.>它不需要重新编译来改变行为.>可以在非开发机器上更改行为.原型开发非常快速,简单,因为您只需在运行时调整逻辑.

本文共计500个文字,预计阅读时间需要2分钟。

Lua在哪些长尾词场景下比C/C++更适用?

我在深入集成Lua并用作一个炫酷的智能配置文件。但我觉得我失去了一些东西,因为人们对Lua的使用感到惊讶。例如,我可以很轻松地解释为什么你可以使用shell脚本而不是C来显示这

我正在嵌入Lua并将其用作一个荣耀的智能配置文件.但是,我觉得我失去了一些东西,因为人们对于Lua的使用感到吃惊.

例如,我可以很容易地解释为什么你可以使用shell脚本而不是C来显示这个例子(诚然,boost regexp是overkill):

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

并将其与:

for foo in *.cpp; do echo $foo; done;

有没有什么例子,你可以给在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 (){ int input; using namespace std; cout << "Enter a number: " ; cin >> input; cout << "factorial: " << fact(input) << endl; return 0; }

LUA:

function fact (n) if n==0 then return 1 else return n * (fact(n-1)) end end print ("enter a number") a = io.read("*number") print ("Factorial: ",fact(a))

在这里,程序看起来是一样的,但是在include,namespace和main()声明中可以清除一些.也删除变量声明和强类型.

现在有人说这是加大一个更大的计划的优势,还是有更多的呢?这与bash示例的方式不同.

Lua在哪些长尾词场景下比C/C++更适用?

使用Lua等脚本语言具有许多其他优点.

Lua对C的几个优点:

由于高层次的性质,开发时间往往较短,如您的例子.>它不需要重新编译来改变行为.>可以在非开发机器上更改行为.原型开发非常快速,简单,因为您只需在运行时调整逻辑.