use lua

lua 复制代码
-- basic.lua
print("hello ".."world")
local a = 1 --only this file can see
b = 2 -- global see
-- not declare vaiable all asign to nil
print(fuck)
-- 字符串可以"" ,'' ,[[]]
-- 一些数值运算支持,进制数,科学数,shift移
function f(a,b)
    print(a,b)
    return a + b,a - b
end

local sum,sub = f(1,2)
--table
local arr = {1,"hell",{},function() end}
-- index start from 1
print(arr[4])
print(#arr)
table.insert(arr,1,"fuck")
local name_table = {
    a=1,
    b="1111",
    c=function ()
        return "yes"    
    end,
    d={}
}
print(name_table["c"])--get the value
--全局表_G
print(_G["table"]["insert"])
print(_G["b"])-- see the above global vaiable b

-- control flow
if 1+1 == 2 then
print(true)
elseif 1+1==3 and 1+1 == 0 then
print(false)--0 is true,only nil is false
else 
    print("what ever")
end

-- start end step
for i=10,1,-1 do
    print(i)--this i just can read not write
    if i == 5 then
        break
    end
end

local n = 10
while n > 1 do
    print(n)
    n = n - 1 --not support -- ++
    if n==5 then
        break
    end
end

-- this module can return varlue
return 1
lua 复制代码
-- multi-file.lua
-- auto run the file basic.lua code
local basic = require("basic")--and get the return from file basic.lua
print("b is ",b)-- get the basic global vaiable b
print(basic)
print(package.path)--?.lua, ?会被文件名替代
lua 复制代码
-- example.lua
local example = {}
function example.hello()
    print("hello")
end
return example
lua 复制代码
-- use-example.lua
local example = require("example")
example.hello()

vscode key bind

  1. Ctrl + e
  2. Home
  3. End
相关推荐
froginwe1117 小时前
Ruby 范围(Range)
开发语言
pipip.18 小时前
Go原生高性能内存网关IMS,比Redis更快
开发语言·redis·golang
AI_567818 小时前
CI/CD自动化部署革命:“三分钟流水线“背后的工程实践
java·开发语言·人工智能·ai·neo4j
云知谷18 小时前
【经典书籍】《代码整洁之道》第六章“对象与数据结构”精华讲解
c语言·开发语言·c++·软件工程·团队开发
dragoooon3418 小时前
[Linux——Lesson23.线程概念与控制:线程基础]
java·开发语言·jvm
xixixi7777718 小时前
攻击链重构的具体实现思路和分析报告
开发语言·python·安全·工具·攻击链
蓝桉~MLGT18 小时前
Python学习历程——模块
开发语言·python·学习
庙堂龙吟奈我何19 小时前
js中哪些数据在栈上,哪些数据在堆上?
开发语言·javascript·ecmascript
武子康19 小时前
Java-169 Neo4j CQL 实战速查:字符串/聚合/关系与多跳查询
java·开发语言·数据库·python·sql·nosql·neo4j
一只小灿灿19 小时前
深入解析 Maven 与 Gradle:Java 项目构建工具的安装、使用
java·开发语言·maven