前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >lua array

lua array

作者头像
用户2458545
发布2022-09-07 11:29:20
9170
发布2022-09-07 11:29:20
举报
文章被收录于专栏:阿牛的牙

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.

代码语言:javascript
复制
#!/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
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019年3月16日 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 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.
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档