lua array
lua Array
2023-06-13 09:12:08 时间
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
相关文章
- Lua语言_lua基本语法
- seata saga模式_lua状态机
- Nginx_lua实现waf
- Lua连续教程之Lua中的数值
- cocos2dx-lua虚拟摇杆方向控制
- Lua连续教程之Lua字符串
- 震惊,Java+ lua = 王炸
- 建立高可用Redis集群:Lua技术实现(redis集群lua)
- 构建基于Lua与Redis的分布式集群(luaredis集群)
- 实现MySQL与Lua的功能性连接(lua连接mysql)
- Lua构建MySQL连接池的简易实现(luamysql连接池)
- array用Redis轻松操控Byte Array(redisbyte)
- Lua轻松操作Redis:让你的应用更高效(lua调用redis)
- 脚本Redis集群构建使用Lua脚本实现优化(redis集群执行lua)
- 提升Redis集群性能使用Lua脚本实现(redis集群使用lua)
- Redis通过Lua脚本实现强大功能(redis运行lua脚本)
- 脚本Redis调试Lua脚本一次完美尝试(redis 调试lua)
- 突破性技术Redis调用Lua脚本实现无缝集成(redis调lua脚本)
- Lua元表与元方法实例讲解