2.1. Lua 팅 ¶
WOW Lua Ruby 크트 하 .
Programming in Lua . 1 .
Lua 환 팅하 .
Lua-Eclipse . (LunarEclipse )
해
5.1.4-35 2010-04-07 13:09
LuaForWindows_v5.1.4-35.exe
LuaForWindows_v5.1.4-35.exe
호. .
Eclipse Profiler Interpreter lua.exe path 해 Eclipse Project Lua파 .
2.2. ¶
WOW 함 .
히 한 한.
UTF-8 한.
한 UNICODE 해 .
: UNICODE 포함하 하한. ... U-00000800 - U-0000FFFF 하??
!! 크 .
: UNICODE 포함하 하한. ... U-00000800 - U-0000FFFF 하??
!! 크 .
.
/////////////////////////////////////////////
package utfencoding;
/////////////////////////////////////////////
package utfencoding;
public class UtfEncoding {
final static char[] first = {
final static char[] middle = {
final static char[] last = {
/**
}'','','','','','','ㅁ','ㅂ','ㅃ','ㅅ','ㅆ','o','ㅈ','ㅉ','ㅊ','ㅋ','ㅌ','ㅍ','ㅎ'
};final static char[] middle = {
'ㅏ','ㅐ','ㅑ','ㅒ','ㅓ','ㅔ','ㅕ','ㅖ','ㅗ','ㅠ','ㅘ','ㅛ','ㅙ','ㅚ','ㅜ','ㅝ','ㅞ','ㅟ','ㅡ','ㅢ','ㅣ'
};final static char[] last = {
'\0','','','','','','','','','','','','','','','ㅁ','ㅂ','','ㅅ','ㅆ','o','ㅈ','ㅊ','ㅋ','ㅌ','ㅍ','ㅎ'
}; /**
- @param args
- /
////////////////////////////////////////
UNICoDE(?)
Eclipse환 Encoding UTF-8.
한 UTF-8 0xACC00 (<- UTF-8시작) 을 빼고 초성 중성 종성을 다음으로 빼온다
한 UTF-8 0xACC00 (<- UTF-8시작) 을 빼고 초성 중성 종성을 다음으로 빼온다
= ( /21 /28)
= ( (%(21*28))/28)
= ( a%28)
= ( (%(21*28))/28)
= ( a%28)
하 .
.
.
2.3. Addon ¶
Hello World!
펴.
펴.
*.toc파.
UI LUA Mapping *.xml
해 *.lua
UI LUA Mapping *.xml
해 *.lua
해
"/World of Warcraft/interface/addons/" 폴 한.
Title
트
Author .
트
Author .
HelloWoW.xml
<UI xmlns="http://www.blizzard.com/wow/ui" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui">
<script file="HelloWoW.lua"/>
<Frame name="HelloWoWFrame">
<Scripts>
</Frame>
</UI>
<script file="HelloWoW.lua"/>
<Frame name="HelloWoWFrame">
<Scripts>
</Frame>
</UI>
HelloWoW.lua
하 Hello WOW! .
2.4. WOW API 해 템 ! ¶
템 템 DB 할 한. WOW템 템 7 . index . . suffix . suffix 템 item index화 한 템 index . ( 확히 )
템 트 한 해 , 템 템 ID 해 .. .
트 템 50760 .
4.2 하 템 트 .
4.2 하 템 트 .
호 템 해 템 페 하 . DB WOW 페 하 . Addon 페 하 했 하 템 템 해 Addon 했.
WOW addon 해 . WOW 하 한 . . Item !! 해 한 .
HelloWoW 해 한
function HelloWoW_ShowMessage()
local baseName
local count = 1
local base = {}
baseName = GetItemInfo(25)
for i=25, 70000 do
end
for i = 1, #base do
endlocal count = 1
local base = {}
baseName = GetItemInfo(25)
for i=25, 70000 do
end
for i = 1, #base do
print(basei)
end 템 호 7 wow템 한 하 하 i item '트' 25 해 1 템 해 base테 한 해 한.
. DB화해 해 해 한. 화 해.
했
템 25 7
템 !
템 . 하 ..
템 !
템 . 하 ..
function HelloWoW_ShowMessage()
local baseName = nil
repeat
until baseName ~= nil
print(baseName)
endrepeat
until baseName ~= nil
print(baseName)
파 해
2.5. Lua ¶
황 UTF-8 트 트 하 표 Lua .
헤 트 한 UTF-8 트 00000000 ~ 01111111 : 1 byte (0 ~ 127) 11000000 ~ 11011111 : 2 bytes (192 ~ 223) 11100000 ~ 11101111 : 3 bytes (224 ~ 239) 11110000 ~ 11110111 : 4 bytes (240 ~ 247) 11111000 ~ 11111011 : 5 bytes (248 ~ 251) 11111100 ~ 11111101 : 6 bytes (252 ~ 253)
함 byte 해 함
function charLen(str) calc = string.byte(str:sub(1,1)) --lua byte char형 환하 0 . if(calc >= 0 and calc <= 127) then return 1 elseif(calc >= 192 and calc <= 223) then return 2 elseif(calc >= 224 and calc <= 239) then return 3 elseif(calc >= 240 and calc <= 247) then return 4 elseif(calc >= 248 and calc <= 251) then return 5 elseif(calc >= 252 and calc <= 253) then return 6 else return 0 end end
한 하 한 3byte.
3byte .
한 .
3byte .
한 .
~lua
Chosung = {"","","","","","","ㅁ","ㅂ","ㅃ","ㅅ","ㅆ","o","ㅈ","ㅉ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"};
Middle = {"ㅏ","ㅐ","ㅑ","ㅒ","ㅓ","ㅔ","ㅕ","ㅖ","ㅗ","ㅠ","ㅘ","ㅛ","ㅙ","ㅚ","ㅜ","ㅝ","ㅞ","ㅟ","ㅡ","ㅢ","ㅣ"};
Last = { "\0","","","","","","","","","","","","","","","ㅁ","ㅂ","","ㅅ","ㅆ","o","ㅈ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"};
function samplingFirst(str)
-- 1110xxxx 10yyyyzz 10zzwwww
local first = string.byte(str:sub(1,1)) - 224 -- 1110xxxx
local second = math.floor((string.byte(str:sub(2,2)) - 128)/4)
local third = math.floor((string.byte(str:sub(2,2))%4)*4 + (string.byte(str:sub(3,3)) - 128)/16)
local fourth = math.floor(string.byte(str:sub(3,3))%16)
local unicode = first * 16* 16* 16 + second * 16 * 16 + third * 16 + fourth
unicode = unicode - 0xAC00
local cho = math.floor(unicode / 21/ 28)
local goong = math.floor((unicode % (21*28))/28)
local jong = math.floor((unicode % 28))
return Chosung[cho+1];
end
한 할 . Lua 3byte 형 '' 환 . " " .
하 "\:\:Aldiana" 한 해 해 해
~lua
function cstc(len, str)
return {type = len, body = str};
end
function makingTable(str)
stringtable = {}
for i = 1, #str do
len = charLen(str:sub(i,i))
if len ~= 0 then -- ..
stringtable[#stringtable+1] = cstc(len, str:sub(i,i+len-1))
end
end
chosungtable = {}
for i, v in ipairs(stringtable) do
if v.type == 3 then
chosungtable[#chosungtable+1] = cstc(v.type, samplingFirst(v.body))
else
chosungtable[#chosungtable+1] = cstc(v.type, v.body)
end
end
return stringtable, chosungtable
end
local a = "\:\:Aldiana"
t,x = makingTable(a)
for i, v in ipairs(t) do
print(v.type .. " " .. v.body)
end
for i, v in ipairs(x) do
print(v.type .. " " .. v.body)
end
:
::Aldiana
ㅋㅅ:ㅇㅇㅇㅅ:Aldiana
템 합
2.6. WOW Slash Command ¶
SlashCommand . ..
/ .
Addon SlashCommand 하 할한.
/ 30
하 30 행.
하 30 행.
팅 하 하 행 하 SlashCommand .
SlashCommand 키 .
SLASH_# = '/' 해
WOW '/' msg function .
~lua
function HelloWoW_OnLoad(self)
SLASH_HelloWoW1 = '/hiw';
SLASH_HelloWoW2 = '/hellow';
SLASH_HelloWoW3 = '/HelloWOW';
SlashCmdList["HelloWoW"] = function (msg)
HelloWoWF(msg)
end
end
function HelloWoWF(msg, editbox) -- 4.
print("Hello WOW")
end
:/hiw
템 : Hello WOW
SlashCmdList[""] = function(msg) 하 SLASH_# = '/' 해
WOW '/' msg function .
3
행하 .
할 String 파 .
2.7. CommandMessageParsing ¶
통해 msg 해
parsing해 하 .
parsing해 하 .
행 해 행 한 flag
Addon 해 WOW 할 . Addon flag 할 . addon 함 하 .
Addon 해 WOW 할 . Addon flag 할 . addon 함 하 .
~lua
SLASH_HelloWoW1 = '/hiw';
SLASH_HelloWoW2 = '/hellow';
SLASH_HelloWoW3 = '/HelloWOW';
flag = false;
function HelloWoW_ShowMessage()
SlashCmdList["HelloWoW"] = function (msg)
HelloWoWF(msg)
end;
end
function HelloWoWF(msg, editbox)
print(msg)
local x;
if string.find(msg,"") then
if flag == false then
x = msg:match("%s(%d+)$");
print(x)
flag = true;
if x then
print(" " .. x .. " !");
else print(" 10 !");
end
else
print(" 행");
end
elseif msg:find("") then
if flag == true then
print(" 합");
flag = false;
else
print(" 행 ");
end
end
end
WOW : /hiw
WOW : 행
WOW : /hiw 50
WOW : 50 !
WOW : /hiw
WOW : 합
WOW : /hiw
WOW : 행
WOW : /hiw
WOW : 10
WOW : /hiw 50
WOW : 행
string.find(msg,"") msg "" 2 nil 한. , if lua nil 한 ( 0 트"") true 한.
Eclipse 테트하 string.find(msg,"") WOW 하 . 하 WOW Addon폴 lua파 할 했 Encoding ANSI. WOW UTF-8 ! -> Encoding UTF-8 해 한. 힘 한.
x = string.match(msg,pattern) pattern msg 해 패 assign (=) 통해 .
x = msg:match("%s(%d+)$");
해하 하 합 합 x .
x = msg:match("%s(%d+)$");
해하 하 합 합 x .
패 . Lua Sub pattern 해 한.
하 하 하 하 .
: 테트 하 !!!
? !! 해!!
? !! 해!!
: 팅 lua파 해 하 .
2.8. FrameEventHandling ¶
.
항 UI
화, Event Handling, UI
WOW API Frame Frame DefaultChatWindow 할 .
Lua Frame CreateFrame 해
frameName
String.
String.
parentFrame
해.
해.
inheritsFrame
할 Frame 하 . ..
할 Frame 하 . ..
newFrame:setScript("OnLoad",funcname)
하 OnLoad 트 funcname 행.
MainFrame .
하 2. 할 활화. CHAT_MSG_CHANNEL 트 .
트 .
RegisterEvent 키 하.
function HelloWoW_ShowMessage()
DEFAULT_CHAT_FRAME:RegisterEvent("CHAT_MSG_CHANNEL");
local function eventHandler(self, event, ...)
if (event == "CHAT_MSG_CHANNEL") then
local arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 = ...;
print(arg1);
end
end
DEFAULT_CHAT_FRAME:SetScript("OnEvent", eventHandler);
end
. 팅 .
트 하 트 팅 "파티","","","" 해 Chat 할 Event 해 .
frame Event 해 트 .
.. xml .
HelloWoW.xml
<UI xmlns="http://www.blizzard.com/wow/ui" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui"> <script file="HelloWoW.lua"/> <Frame name="HelloWoW"> <Scripts> <OnLoad> HelloWoW_ShowMessage(self) </OnLoad> </Scripts> </Frame> </UI>self !! self Frame .
On_load HelloWoW 행킨.
HelloWoW.lua
function HelloWoW_ShowMessage(self)
local frame = self;
frame:RegisterEvent("CHAT_MSG_CHANNEL");
frame:RegisterEvent("CHAT_MSG_SAY");
frame:RegisterEvent("CHAT_MSG_PARTY");
frame:RegisterEvent("CHAT_MSG_YELL");
frame:RegisterEvent("CHAT_MSG_GUILD");
print("Load OK")
local function eventHandler(self, event, ...)
if (event == "CHAT_MSG_CHANNEL" or event == "CHAT_MSG_SAY") then
local arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 = ...;
print(arg1);
print(arg2);
end
end
frame:SetScript("OnEvent", eventHandler);
end
하 트 한
frame:RegisterEvent("CHAT_MSG_CHANNEL");
frame:RegisterEvent("CHAT_MSG_SAY");
frame:RegisterEvent("CHAT_MSG_PARTY");
frame:RegisterEvent("CHAT_MSG_YELL");
frame:RegisterEvent("CHAT_MSG_GUILD");
CHAT_MSG_CHANNEL CHAT_MSG_SAY 하 . 행하 Load_OK 하 행.
팅 print해.
eventHandler(self, event, ...)
self 트 frame 하 event 해 트. ... arg1~arg9 Communication Event arg1 msg arg2 author .
.
2.9. Update함 timer ¶
행 하 Addon.
Timer ?
WOW API 해 getTime()..
.
.
~lua
seconds = GetTime();
print("Current system uptime is: "..seconds.." seconds!");
API. Addon Sleep 템 . Sleep 했. 하 하 ? Sleep Lua System함 패키 OS 해 .
Lua 홈페 .
Lua 한 환 sleep .
Coroutine 해 한 하.
Coroutine 하? 하. Busy Wait Sleep 해 하 Thread해 ???
.
~lua
local clock = os.clock
function sleep(n) -- seconds
local t0 = clock()
while clock() - t0 <= n do end
end
co = coroutine.create(function()
print("what")
sleep(5)
end
)
print("what")
print("main",coroutine.resume(co));
행하 what . sleep(5) 하 5 행. . Millisecond .
Coroutine Thread main . .. .
2 0.1 0.2 Check 해 함 해.
OnUpdate Event 하
{{{
How Often Is It Called
The game engine will call your OnUpdate function once each frame. This is (in most cases) extremely excessive.
Ctrl + R to see the FPS on screen.
}}
FPS... Frame Per Second . 1/60 한 .
OnUpdate Frame 하 해.
{{{
<UI xmlns="http://www.blizzard.com/wow/ui" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui">
<script file="HelloWoW.lua"/>
<Frame name="HelloWoW">
<Scripts>
<OnLoad>self.TimeSinceLastUpdate = 0 </OnLoad>
<OnUpdate function="HelloWoW_OnUpdate"></OnUpdate>
</Scripts>
</Frame>
</UI>
}}}
Frame OnUpdate OnUpdate 행 HelloWoW_OnUpdate 함 행해.
행해..?
{{{
function HelloWoW_OnUpdate(self, elapsed)
self.TimeSinceLastUpdate = self.TimeSinceLastUpdate + elapsed;
if (self.TimeSinceLastUpdate > MyAddon_UpdateInterval) then
--
-- Insert your OnUpdate code here
--
TimeSet();
self.TimeSinceLastUpdate = 0;
end
end
function TimeSet(){
seconds = GetTime();
print("Current system uptime is: "..seconds.." seconds!");
}
}}}
...
행 ?
.
{{{
When Is It Called Edit
OnUpdate is not called on any hidden frames, only while they are shown on-screen. OnUpdate will also never be called on a virtual frame, but will be called on any frames that inherit from one.
}}}
Frame . .. Frame 하 .
WOW Addon Studio .
WOW Addon Studio WOW Addon UI 트 헨 한 툴.
Addon Studio 크 V1.0.1 V2.0
1.0.1 Visual Studio 2008 하 V2.0 Visual Studio 2010 한 히 V2.0 하 .
트 http://www.codeplex.com/WarcraftAddOnStudio .
Basic Addon UI ACE UI 해.
Project Visual Studio Frame 하 Frame 하 Properties EventHandling 하 .
트 Create Function 할 Lua파 Script .
..
OnUpdate 할 함 툴 하 하
{{{
Frame.xml
<Ui xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.blizzard.com/wow/ui/">
<Script file="Frame.lua" />
<Frame name="Frame1" parent="UIParent" toplevel="true" movable="true" enableMouse="true">
<Size>
<AbsDimension x="359" y="303" />
</Size>
<Anchors>
<Anchor point="TOPLEFT">
<Offset>
<AbsDimension x="100" y="-47" />
</Offset>
</Anchor>
</Anchors>
<Scripts>
<OnUpdate>Frame1_OnUpdate();</OnUpdate>
<OnMouseDown>self:StartMoving();</OnMouseDown>
<OnMouseUp>self:StopMovingOrSizing();</OnMouseUp>
</Scripts>
<Backdrop bgFile="Interface\DialogFrame\UI-DialogBox-Background" edgeFile="Interface\DialogFrame\UI-DialogBox-Border" tile="true">
<BackgroundInsets>
<AbsInset left="11" right="12" top="12" bottom="11" />
</BackgroundInsets>
<TileSize>
<AbsValue val="32" />
</TileSize>
<EdgeSize>
<AbsValue val="32" />
</EdgeSize>
</Backdrop>
</Frame>
</Ui>
}}}
.
{{{
Frame.lua
-- Author : June
-- Create Date : 2011-08-12 2:23:05
function Frame1_OnUpdate()
--put your event handler logic here
seconds = GetTime();
print("Current system uptime is: "..seconds.." seconds!");
end
}}}
{{{
## X-AutoGenerated: true
## X-GeneratorComment: Basic project properties and project files will be automatically added during deployment. Properties added by the user will be copied without changes.
## Interface: 40200
## Title: WowAddon1
## Notes: Basic WoW Addon
## Author: June
## Version: 0.1Beta
Frame.xml
Frame.lua
}}}
.
해 해 60회 Time 크하 .
..
!!!
할 :
== ==










