美文网首页
lua安装使用

lua安装使用

作者: 明明就_c565 | 来源:发表于2018-11-20 17:44 被阅读0次

说明

常用脚本语言比较,在给软件提供嵌入式脚本编程能力上,Lua是绝佳选择。如果需要脚本语言功能强大,Python是绝佳选择。Ruby在网络方面的库比较多,而Perl长于字符串处理,可以说他们各有千秋。

安装

curl -R -O http://www.lua.org/ftp/lua-5.3.5.tar.gz

tar zxf lua-5.3.5.tar.gz

cd lua-5.3.5

make linux test

编译报错

lua.c:82:31: fatal error: readline/readline.h: No such file or directory

解决方法

缺少libreadline-dev依赖包

centos: yum install readline-devel -y

debian: apt-get install libreadline-dev.

http://www.vcerror.com/?p=1786

使用

测试文件  hello.lua

#!/usr/bin/lua

--[[

author:heweiwei

date:2018

--]]

--my first code

print("hello,world")

my_age = 18

print("my_age=",my_age)

my_age = nil

print("my_age=",my_age)

print(type("Hello world"))      --> string

print(type(10.4*3))            --> number

print(type(print))              --> function

print(type(type))              --> function

print(type(true))              --> boolean

print(type(nil))                --> nil

print(type(type(X)))            --> string

运行

[heweiwei@CentOS7 lua]$ lua hello.lua

hello,world

my_age= 18

my_age= nil

string

number

function

function

boolean

nil

string

测试文件 func.lua

#!/usr/bin/lua

function jc(num)

    if num == 0 then

        return 1

    else

        return num * jc(num-1)

    end

end

print(jc(5))

fun = jc

print(fun(10))

function fun1(tb,fun)

    for k ,v in pairs(tb) do

        print(fun(k,v))

    end

end

tab = {}

tab["name"] = "heweiwei"

tab["city"] = "shanghai"

tab["like"] = "code"

fun1(tab,

function(k,v)

    return k.."="..v

end

)

运行

[heweiwei@CentOS7 lua]$ lua func.lua

120

3628800

like=code

city=shanghai

name=heweiwei

简单教程

http://www.runoob.com/lua/lua-tutorial.html

相关文章

网友评论

      本文标题:lua安装使用

      本文链接:https://www.haomeiwen.com/subject/mfrxqqtx.html