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/드명" 로 더가 만들다.
Interface는 보가 들가다.
http://www.wowwiki.com/Getting_the_current_interface_number
로 보를 볼 다.
내가 는 4.2까 40200겠 보를 놓면 드 로드 '구'로 대로 로드가 될 다.
http://www.wowwiki.com/Getting_the_current_interface_number
로 보를 볼 다.
내가 는 4.2까 40200겠 보를 놓면 드 로드 '구'로 대로 로드가 될 다.
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를 러! ¶
WOW는 WOW API를 개는 wiki를 가고 고 API를 가보면 다것들 다.
http://www.wowwiki.com/World_of_Warcraft_API
또 Widget과 LuaFunction 보를 볼 다.
http://www.wowwiki.com/World_of_Warcraft_API
또 Widget과 LuaFunction 보를 볼 다.
기 기본 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로 바로 뒤 몇바를 는 문 보는 를 가고 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 는 볼 다. .. 모든 가 맞다!!! 다 : 로그램 나리 및 구 == 남기고 말 ==