## 技巧1:
~~~
local a = {};
function b()
print("Hello World")
end
a["sell"] = {callFunc =b}
a["sell"].callFunc()
~~~
#
## 技巧2:
使用lua 自帶的 unpack :
解釋:把一直數組(只有連續數字下標的 table)展開成一串返回值,但是對用字符串或別的東西做 key 的 table 無能為力。
~~~
function unpackex(tbl, args)
local ret = {}
for _,v in ipairs(args) do
table.insert(ret, tbl[v])
end
return unpack(ret)
end
print(unpackex({one = {"one", "two", "three"}, two = "T" , three = "TH"},{"one", "two", "three"}))
~~~
輸出:>> ?table: 00ABC2D0TTH
- 前言
- lua學習筆記之一(C/C++程序員的Lua快速入門[初階話題])
- lua學習筆記之二(C/C++程序員的Lua快速入門[進階話題])
- lua學習筆記之三(C/C++程序員的Lua快速入門[高階話題])
- lua學習筆記之四(Lua中的基本函數庫)
- lua學習筆記之五(Lua中的數學庫)
- Lua中的table函數庫
- Lua中的常用操作系統庫
- LUA string庫
- LUA IO庫
- VS2010編譯Lua程序(lua-5.2.3)
- Lua中調用C函數(lua-5.2.3)
- Lua 常用數據結構
- lua 如何輸出樹狀結構的table?
- Lua中的元表與元方法
- lua 函數回調技巧
- Cocos2d-x使用Luajit實現加密
- Lua中的模塊與module函數
- 我所理解lua 語言中的點、冒號與self
- Lua代碼編寫規范