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
相关推荐
无限的鲜花5 小时前
反射(原创推荐)
java·开发语言
yongche_shi5 小时前
ragas官方文档中文版(五十)
开发语言·python·ai·ragas·如何评估和改进 rag 应用
一路向北he5 小时前
字节钢铁军团--“提供情境,而非控制”
java·开发语言·前端
AI行业学习6 小时前
Notepad++ 官方下载 + 完整安装 + 全套优化配置(2026最新)
开发语言·人工智能·python·前端框架·html·notepad++
大圣编程7 小时前
Python中continue语句的用法是什么?
开发语言·前端·python
upgrador8 小时前
基础知识:C++ STL构造函数的左闭右开惯例及其实现原理
开发语言·c++
yoothey9 小时前
报废审批流规则引擎设计——责任链模式完整实现
linux·开发语言·bash
geovindu9 小时前
python: Functional Options Pattern
开发语言·后端·python·设计模式·惯用法模式·函数式选项模式
wuyk5559 小时前
24. C 语言模块化:不是拆几个.c 文件那么简单
c语言·开发语言·stm32·单片机
凯瑟琳.奥古斯特10 小时前
K次取反最大化数组和解法(力扣1005)
开发语言·c++·算法·leetcode·职场和发展