lua 函数回调技巧

it2025-06-16  8

技巧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: 00ABC2D0 T TH

转载于:https://www.cnblogs.com/bhlsheji/p/5175061.html

最新回复(0)