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
相关推荐
开开心心_Every4 分钟前
黄金价格软件国内外价格实时监控超方便
运维·服务器·游戏·智能手机·pdf·lua·perl
YSL0701248 分钟前
一文通关-----栈和队列
开发语言·数据结构
维克兜率天18 分钟前
【维克】统计套利建模:从因子到信号的完整流程
android·开发语言·python·算法·kotlin
Pin_Qing23 分钟前
同一天,谷歌半价卖旗舰,阶跃翻倍收缓存
大数据·开发语言·人工智能·程序人生·缓存
2501_9307077828 分钟前
使用C#代码在 Word 文档中添加、插入或删除页面
开发语言·c#·word
没有梦想的咸鱼185-1037-166332 分钟前
从通量数据到SCI论文——AI-R语言生态系统碳水热通量及其机制分析与论文
开发语言·人工智能·数据分析·r语言
weixin_4617694038 分钟前
conda create 创建容器 Failed to resolve ‘repo.anaconda.com‘问题
开发语言·python·conda·repo·网络问题·无法创建
Want59539 分钟前
Python生日蛋糕
开发语言·python
C语言小火车1 小时前
C++ 为什么越来越依赖标准库?
java·开发语言·c++
郝学胜-神的一滴1 小时前
金融数据分析实战:从数据清洗到策略回测,Python全链路落地
开发语言·python·程序人生·金融·数据挖掘·数据分析