[問題] Lua在函數中產生資料與讀取問題

看板Programming作者 (五黑)時間16年前 (2008/02/09 07:43), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/9 (看更多)
function a() a = () if a[0] == nil then print("foo") a[0] = () b(a[0]) if a[0] == nil then print("foo") else print("ok") end c(a[0]) else print("ok") end end function b(a) a = (1, 2) end function c(a) if a == nil then print("nil") else print("foo ") print(a[0] .. a[1]) end end a() 以上, 從a函式丟一個變數a, 在b函式產生一對資料指派給此變數, 在c函式打算 做該變數的資料處理. 但是印出的答案盡是foo foo foo, 果如其所說的what the fuck! 印出訊息也是 "attempt to index local <variable-name>" 我知道那是某個函數的local變數, 可是一旦要取用, 我只想要它的值, 而不是它這個物件的參考!! 你這個白痴Lua一直給我參考到那個Local幹嘛? 不是已經結束函式了嗎? 不是已經跳出scope外了嗎? 你不講我還真不知道,原來我很想取用一個local變數, 直接告訴我在此區域看不見那個東西就好了,囉唆那麼多幹嘛? 寫個Lua程式,架構大一點,隨機性多一點, 最後就因為這種attempt to index LOCAL 而 *完全* 寫不下去. 超爛的程式語言! 找了半天找不出答案, 氣到輕輕一拳把鍵盤一角打碎了! 看到鬼! 有沒有什麼辦法讓一個函式(像上述函式b)內部產生的資料能在其它函式中取用? -- 鄉民A:灌C可以搞阿嬌啊?

我的Visual C++光碟哪裏去了?
-- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.231.71.148 ※ 編輯: oohay 來自: 61.231.71.148 (02/09 07:45)
文章代碼(AID): #17hEaYZQ (Programming)
討論串 (同標題文章)
以下文章回應了本文
完整討論串 (本文為第 1 之 9 篇):
文章代碼(AID): #17hEaYZQ (Programming)