1
我想這樣做的邏輯,如:錯誤處理Lua中
local function create(...)
for k, v in ipairs{...} do
if k == "player" then
_player = v
end
end
if _player == nil then
**error**("It nil") -- stop running here and throw the error
end
end
不lua有類似的東西在這裏誤差函數?
在這段代碼中'k'永遠不會是字符串'player'。 「ipairs」返回的第一個值是數字索引。 –
@Etan Reisner,明白了,我可以在這裏使用pairs()...嗎?否則有沒有辦法傳遞字符串鍵? – 1hunch1kill
你打算如何調用'create'函數? 'create(「player」,arg1,arg2,arg2)'? 'create({player =「something」,attr1 = val1,attr2 = val2})? –