mongona

mongona
-- --
正在获取天气

lua array

What is Lua?


     Lua is a powerful, efficient, lightweight, embeddable scripting language. It supports procedural programming, object-oriented programming, functional programming, data-driven programming, and data description.

    Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting bytecode with a register-based virtual machine, and has automatic memory management with incremental garbage collection, making it ideal for configuration, scripting, and rapid prototyping.

#!/usr/bin/lua

-- lua 的数组
-- 
-- 一维数组 可以用table(表) 表示
array = {'lua', 'python', 'go', 'c'}

print(array) --> table  address
-- lua 索引从1 开始  #变量--> 拿长度
for i = 1, #array do
    print(array[i])
end

array = {}

-- 赋值
for i = -2, 2 do
    array[i] = i * 2
end

-- 读取数值
for i = -2, 2 do
    print(array[i])
end

-- 多维数组
-- 10 x 10 数组
-- 
-- 初始化数组

array = {}

for i = 1, 10 do
    array[i] = {}
    for j = 1, 10 do
        array[i][j] = j
    end

end

print(array) -- 返回内存地址

-- 访问数组
for i = 1, 10 do
    print(array[i])
    for j = 1, 10 do 
        print(array[i][j])

    end
end


 

0
0
Tags
lua
富强,民主,文明,和谐,自由,平等,公正,法治,爱国,敬业,诚信,友善。
打赏二维码
About
Sato
有一个人养了几条鱼死了,悲伤不已,他不想土葬,他说想给他火葬,把鱼灰撒回海洋让它回到母亲的怀抱……谁知道越烤越香,后来他就买了瓶啤酒…… 很多事情,走着走着就忘了初衷…… 几乎每个人都听过:“不忘初心,方得始终”,却少有人知道下一句:“初心易得,始终难守”。 人生是一场修行,很少有人能忠于自己内心的目标和生命的使命,因此善始者多,善终者少。
Category
Tags
Site statistics

本站现有文章16篇,共被浏览7897

本次响应耗时: 0.453s

当前来路IP: 54.147.29.160  美国

您是本站第: 46148 位访客!

本站已苟活: 

All hots
Article archiving