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
相关推荐
你怎么知道我是队长10 分钟前
JavaScript的自适应效果
开发语言·javascript·ecmascript
mayaairi1 小时前
JS数组完全指南(含十大操作详解)
开发语言·前端·javascript
j7~1 小时前
【数据结构初阶】队列的实现(链式队列 + 循环队列)--详解
c语言·开发语言·数据结构·学习·队列·queue·c\c++
king_linlin1 小时前
算法基础——算法复杂度
c语言·开发语言·数据结构·算法
二十雨辰1 小时前
[爬虫]-解析
开发语言·python
zzq77971 小时前
Android 16 API 36 升级后 APP 加固兼容性问题解析
android·开发语言·安全·kotlin·安卓·安全架构
keyipatience2 小时前
日志和线程池
java·开发语言
码云数智-园园2 小时前
建站平台有哪些?建站工具怎么选
开发语言
nVisual2 小时前
01-环境监控集成方案
运维·服务器·开发语言·网络·数据库·数据中心布线·综合布线管理软件
此生决int2 小时前
深入理解C++系列(04)——类和对象(下)
开发语言·c++