lua 常見lua報錯型別 自用收藏

2021-10-13 21:06:30 字數 2186 閱讀 7336

attempt to index a nil value (global 『a』)

試圖引用乙個空值

attempt to index a nil value (field 『name』)

這裡的aa是數字型別,無法用.去引用

aa =

1aa.name =

"hah"

--試圖引用乙個空值

aa.name.first =

"haha"

--aa

attempt to perform arithmetic on a nil value (global 『a』)

試圖用乙個空值進行計算

a=

nilprint

(a+1

)

attempt to perform arithmetic on a nil value (global 『a』)

試圖用乙個空值進行計算

a=

nilprint

(a+1

)

attempt to perform bitwise operation on a nil value (global 『a』)

試圖用空值進行位運算

a=

nilprint

(a &

1)

attempt to perform arithmetic on a nil value (field 『b』)

試圖用乙個不存在的引用進行計算

a =

print

(a.b &

1)

attempt to call a nil value (global 『a』)

設定a為空,將其以函式的形式呼叫

a=

nila

()

attempt to call a nil value (field 『b』)

呼叫不存在的子屬性或者函式

a=a.f

()

attempt to perform arithmetic on a string value (global 『a』)

試圖用非數字型別進行計算

a=

"str"

print

(a+1

)

attempt to perform arithmetic on a table value (global 『a』)

試圖利用table型別進行數學計算

a =

print

(a+1

)

attempt to perform arithmetic on a string value (field 『s』)

企圖用某個變數的字元子屬性進行數**算

a =

print

(a.s +

1)

attempt to perform arithmetic on a table value (field 『s』)

試圖對某個table型別的子屬性進行計算,類似於2

a =

}print

(a.s +

1)

stack overflow (函式呼叫棧超限 luai_maxstack 1000000)

functiona(

)b()

endfunctionb(

)a()

enda

()

upvalue數量限制

lua的upvalue是有上限的,這個上限定義在luaconf.h中:

如果local變數太多,還是放到table裡面吧

#define luai_maxupvalues    60
引數個數限制

區域性變數個數限制

#define luai_maxvars        200
字串拼接個數限制

lua三種字串拼接效能分析

常見lua報錯型別

lua筆記 lua資料型別轉換

tostring 可以將布林型別和數值型別轉換為字串型別,示例 local value true print tostring value 輸出 true local num1 10 local num2 10.0 local num3 10.03 print tostring num1 輸出 10...

Lua函式呼叫報錯

之前的專案開發中有聽到同事提及過有一種寫法函式在呼叫時會報錯,今天在看書的過程中又看到了,記錄下來 local funa function n if n 0 then return 1 else return n funa n 1 endendprint funa 5 例如上面的 我們想求1 2 3...

Lua資料型別

lua注釋 單行注釋 print helloworld 多行注釋 print www.w3cschool.cc print helloworld 識別符號 標示符以乙個字母a到z或a到z或下劃線 開頭加上0個或多個字母,下劃線,數字 0到9 最好不要使用下劃線加大寫字母的標示符,因為lua的保留字也...