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
相关推荐
三玖诶4 分钟前
如何在 Qt 的 QListWidget 中为某一行添加点击事件
开发语言·qt
InJre10 分钟前
QT widgets 窗口缩放,自适应窗口大小进行布局
开发语言·qt·ui
可愛小吉13 分钟前
Python 课程10-单元测试
开发语言·python·单元测试·tdd·unittest
五味香25 分钟前
C++学习,动态内存
java·c语言·开发语言·jvm·c++·学习·算法
无名之逆26 分钟前
计算机专业的就业方向
java·开发语言·c++·人工智能·git·考研·面试
爱棋笑谦33 分钟前
二叉树计算
java·开发语言·数据结构·算法·华为od·面试
翔云API1 小时前
人证合一接口:智能化身份认证的最佳选择
大数据·开发语言·node.js·ocr·php
jimmy.hua1 小时前
C++刷怪笼(5)内存管理
开发语言·数据结构·c++
xiaobai12 31 小时前
二叉树的遍历【C++】
开发语言·c++·算法
DieSnowK1 小时前
[项目][WebServer][Makefile & Shell]详细讲解
开发语言·c++·http·makefile·shell·项目·webserver