【正文】
print(“i is now “ .. i) if i 2 then print(“small”) elseif i 4 then print(“medium”) else print(“big”) end end 運(yùn)行結(jié)果 i is now 1 small i is now 2 medium i is now 3 medium i is now 4 big i is now 5 big 數(shù)組的使用 Arrays myData = {} myData[0] = “foo” myData[1] = 42 Hash tables myData*“bar”+ = “baz” Iterate through the structure for key, value in myData do print(key .. “=“ .. value) end 輸出結(jié)果 0=foo 1=42 bar=baz Table的嵌套 Table ‘constructor’ myPolygon = { color=“blue”, thickness=2, npoints=4。 Visual Studio載入 Lua庫(kù) 基礎(chǔ)函數(shù) Lua提供的基礎(chǔ)函數(shù)。所有在 lua_前綴。 所有在其中定義的函數(shù)等都以 luaL_打頭(例如,luaL_loadbuffer)?;A(chǔ) API致力于 economy and orthogonality,相反 auxlib致力于實(shí)現(xiàn)一般任務(wù)的實(shí)用性。需要銘記在心的是, auxlib沒(méi)有存取 Lua內(nèi)部的權(quán)限。 頭文件 。 Lua調(diào)用 C DLL include include include include /*定義函數(shù) */ static int MyLuaDLL_HelloWorld(lua_State* L) { MessageBox(NULL,Hello,World,MB_OK)。 } static int MyLuaDLL_average(lua_State *L) { /* get number of arguments */ int n = lua_gettop(L)。 int i。 i = n。 } /* push the average */ lua_pushnumber(L, sum / n)。 /* return the number of results */ return 2。 int __cdecl __declspec(dllexport) luaopen_MyLuaDLL(lua_State* L) { luaL_openlib(L, MyLuaDLL, MyLuaDLLFunctions, 0)。 } local testlib = (,luaopen_MyLuaDLL)。 else Error end ()。 print(average:,a,sum:,b