# Lua眉角
* 將global變數宣告成local
* 使用module之後, 無法取得global的內容, 透過區域變數才能夠繼續存取
* [https://www.cnblogs.com/lightsong/p/5743188.html](https://www.cnblogs.com/lightsong/p/5743188.html)
* 範例
```
local print = print
module("uiRank", package.seeall)
ABC()
function ABC()
print("ABC")
end
```
---
* 某專案的lua, 每個功能的邏輯入口都會呼叫 **init()** 的觸發點
* 以 uiRank 為例, 觸發點是 **delSingletonWnd()**, prefab初始化結束會呼叫 **wnd:init(unpack(args))**
*uiRank.lua*
```
module("uiRank", package.seeall)
declSingletonWnd(uiRank, "ui/uiRank")
function init(self)
...
end
```
*WndClass.lua*
```
function declWnd(derive, resourcePath, base)
...
derive.initWithPrefab = function(wnd, prefab, ...)
...
wnd.__class = derive._NAME
wnd.core = core
wnd.tf = core.transform
wnd:innerInit()
wnd:init(unpack(args))
wnd:onActive()
wnd:onForeground(unpack(args))
wnd.isOpened = true
...
end
...
end
```
---
* **.** 和 **:** 的差異
* The colon is for implementing methods that pass self as the first parameter. So x:bar(3,4)should be the same as x.bar(x,3,4). [來源](https://stackoverflow.com/questions/4911186/difference-between-and-in-lua)
* [OO教學](https://www.lua.org/pil/16.html) 文章內有兩種差異的範例
---
* command line 透過 luajit 將 lua 編譯成 byte 檔
* [luajit無法編譯的解決方法](https://www.javatt.com/p/41787)
---
###### tags: `Lua`