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
相关推荐
程序员黄同学1 小时前
如何实现单例模式?
开发语言·javascript·ecmascript
DevangLic1 小时前
【STL 之速通pair vector list stack queue set map 】
开发语言·c++·蓝桥杯·list
洛克希德马丁1 小时前
Qt饼状图在图例上追踪鼠标落点
开发语言·qt·计算机外设
王哈哈嘻嘻噜噜1 小时前
c++中的auto关键字
开发语言·c++
江沉晚呤时1 小时前
C# 状态模式深度解析:构建灵活的状态驱动系统
开发语言·javascript·数据库·ui·ajax·c#·ecmascript
邪恶的贝利亚1 小时前
如何深刻理解Reactor和Proactor
开发语言·php
邪恶的贝利亚2 小时前
c++造轮子之REACTOR实战
开发语言·c++·php
暴龙胡乱写博客2 小时前
python三大库之---pandas(二)
开发语言·人工智能·python·pandas
lsx2024062 小时前
R Excel 文件:高效数据处理与可视化工具的完美结合
开发语言