• 0

    posted a message on Updates not pushing to Curse

    The suggestion works for me, but need wait several hours.

    Posted in: General Chat
  • 0

    posted a message on Silence Blizz function with pcall select fails

    You forget the return, and the pcall's first return value is a flag

    local _, SavedToyType  = pcall(function() return (select(2, GetActionInfo(1) )) end) 
    Posted in: Lua Code Discussion
  • 0

    posted a message on Help with regex expression

    Well, I think the code should be like :

     

    function Parse(text)
    	local count, size, modifier = text:match("^!(%d+)[dD](%d+)+?(%d*)$")
    
    	count = tonumber(count)
    
    	-- There is no match
    	if not count then return end
    
    	size = tonumber(size)
    
    	-- The modifier may be nil even matched
    	modifier = tonumber(modifier) or 0
    
    	local ret = 0
    	for i = 1, tonumber(count) do ret = ret + math.random(size) end
    
    	return ret + modifier
    end
    
    -- nil
    print( Parse("!2e10") )
    
    -- 12
    print( Parse("!2d10") )
    
    -- 112
    print( Parse("!2D10+100") )

     

     
    Posted in: AddOn HELP!
  • 0

    posted a message on Help with regex expression

    > ("!5d6"):gsub("^!?(%d+)[dD](%d+)+?(%d*)$", print)
    5 6
    > ("!5d6+3"):gsub("^!?(%d+)[dD](%d+)+?(%d*)$", print)
    5 6 3
    > ("5d6+3"):gsub("^!?(%d+)[dD](%d+)+?(%d*)$", print)
    5 6 3
    > ("5d6"):gsub("^!?(%d+)[dD](%d+)+?(%d*)$", print)
    5 6

     

    It's this what you want?

    Posted in: AddOn HELP!
  • 0

    posted a message on How to rotate a texture and fill
    Here is an example code for rotation with the current texcoord settings for any angle, I also use it for my range indicator on raid panel.

    __OriginTexCoord is used to keep the texcoord settings, so if change the texture or SetTexCoord, just clear it from the texture object.

    I hope it can help you.

            --[======[
    		@name RotateRaid
    		@type method
    		@desc Rotate texture for radian with current texcoord settings
    		@param radian number, the rotation raidian
    		@return nil
    	]======]
    	function RotateRadian(self, radian)
    		if type(radian) ~= "number" then
    			error("Usage: Texture:RotateRadian(radian) - 'radian' must be number.", 2)
    		end
    
    		if not self.__OriginTexCoord then
    			self.__OriginTexCoord = {self:GetTexCoord()}
    			self.__OriginWidth = self:GetWidth()
    			self.__OriginHeight = self:GetHeight()
    		end
    
    		while radian < 0 do
    			radian = radian + 2 * math.pi
    		end
    		radian = radian % (2 * math.pi)
    
    		local angle = radian % (math.pi /2)
    
    		local left = self.__OriginTexCoord[1]
    		local top = self.__OriginTexCoord[2]
    		local right = self.__OriginTexCoord[7]
    		local bottom = self.__OriginTexCoord[8]
    
    		local dy = self.__OriginWidth * math.cos(angle) * math.sin(angle) * (bottom-top) / self.__OriginHeight
    		local dx = self.__OriginHeight * math.cos(angle) * math.sin(angle) * (right - left) / self.__OriginWidth
    		local ox = math.cos(angle) * math.cos(angle) * (right-left)
    		local oy = math.cos(angle) * math.cos(angle) * (bottom-top)
    
    		local newWidth = self.__OriginWidth*math.cos(angle) + self.__OriginHeight*math.sin(angle)
    		local newHeight = self.__OriginWidth*math.sin(angle) + self.__OriginHeight*math.cos(angle)
    
    		local ULx	-- Upper left corner X position, as a fraction of the image's width from the left (number)
    		local ULy 	-- Upper left corner Y position, as a fraction of the image's height from the top (number)
    		local LLx 	-- Lower left corner X position, as a fraction of the image's width from the left (number)
    		local LLy 	-- Lower left corner Y position, as a fraction of the image's height from the top (number)
    		local URx	-- Upper right corner X position, as a fraction of the image's width from the left (number)
    		local URy 	-- Upper right corner Y position, as a fraction of the image's height from the top (number)
    		local LRx 	-- Lower right corner X position, as a fraction of the image's width from the left (number)
    		local LRy 	-- Lower right corner Y position, as a fraction of the image's height from the top (number)
    
    		if radian < math.pi / 2 then
    			-- 0 ~ 90
    			ULx = left - dx
    			ULy = bottom - oy
    
    			LLx = right - ox
    			LLy = bottom + dy
    
    			URx = left + ox
    			URy = top - dy
    
    			LRx = right + dx
    			LRy = top + oy
    		elseif radian < math.pi then
    			-- 90 ~ 180
    			URx = left - dx
    			URy = bottom - oy
    
    			ULx = right - ox
    			ULy = bottom + dy
    
    			LRx = left + ox
    			LRy = top - dy
    
    			LLx = right + dx
    			LLy = top + oy
    
    			newHeight, newWidth = newWidth, newHeight
    		elseif radian < 3 * math.pi / 2 then
    			-- 180 ~ 270
    			LRx = left - dx
    			LRy = bottom - oy
    
    			URx = right - ox
    			URy = bottom + dy
    
    			LLx = left + ox
    			LLy = top - dy
    
    			ULx = right + dx
    			ULy = top + oy
    		else
    			-- 270 ~ 360
    			LLx = left - dx
    			LLy = bottom - oy
    
    			LRx = right - ox
    			LRy = bottom + dy
    
    			ULx = left + ox
    			ULy = top - dy
    
    			URx = right + dx
    			URy = top + oy
    
    			newHeight, newWidth = newWidth, newHeight
    		end
    
    		self:SetTexCoord(ULx, ULy, LLx, LLy, URx, URy, LRx, LRy)
    		self:SetWidth(newWidth)
    		self:SetHeight(newHeight)
    	end
    
    Posted in: Lua Code Discussion
  • 0

    posted a message on In-Game Addon System (IGAS)
    do
        -- a light-weighted class
        myclass = {}
    
        function myclass:methodA()
        end
    
        meta = {__index = myclass}
    
        function createObject()
            return setmetatable({}, meta)
        end
    
        -- we create 1000 object
        collectgarbage()
    
        collectgarbage('stop')
    
        memory = collectgarbage('count')
    
        for i = 1, 10000 do
            obj = createObject()
        end
    
        print(collectgarbage('count') - memory)
    
        collectgarbage('restart')
    end


    Well, I run that code in the osx, it's also 625, maybe for 64 bit version.

    The example I used before, is for a light-weighted inheritance design, so class B inherit from class A, you can't just set the metatable from A to B. The best way is just store the class's method into it, or you may need a complex metatable system like IGAS.

    So, the memory cost is not the problem, IGAS's object would cost a little more cpu usage, but I don't think it's a real problem.
    Posted in: Libraries
  • 0

    posted a message on In-Game Addon System (IGAS)
    A document system is working on for comments and quick document view now.

    The basic system may not be good for learning, I try to build a system from the basic, so many things in the root part has no meanings for addon development.

    Making addon doesn't mean to build classes and others yourself, there is no class definition in the Addon Cube, and some other my addons.

    To build a Form contains a editor can just use the build-in widget classes such like :

    import "System"
    
    local form = System.Widget.Form("MyForm")
    
    local editor = System.Widget.CodeEditor("MyEditor", form)
    editor:SetPoint("TOPLEFT", 4, -26)
    editor:SetPoint("BOTTOMRIGHT", -4, 26)


    What a System.Widget.Form class done, is like the acegui to provide a well designed ui element for using. For normal authors, there is no need to make their classes. At first time, IGAS is designed to build these ui element prototypes in an easy way.

    The complex part is only about how to create an object, but since an object only will be created once, the cost could be ignored.

    About the usage , I can't give you a benchmark, but a simple test, run in lua 5.1(mac) :

    About the cpu usage :
    require "igas"
    
    pow = math.pow
    
    -- Use this to increase the usage of the function body
    MultiCount = 100
    
    -- Normal function the same with class Multi's Result method
    function Result(value)
        for i = 1, MultiCount do
            value = pow(value, 2)
        end
        return value
    end
    
    do
        class "Multi"
            -- Method
            function Result(self)
                local value = self.Value
                for i = 1, _G.MultiCount do
                    value = pow(value, 2)
                end
                return value
            end
    
            function Multi(self, value)
                self.Value = value or 0
            end
        endclass "Multi"
    end
    
    function a(count)
        local time = os.clock()
        
        for i = 1, count do
            r = Result(i)
        end
    
        print("Finish for normal", os.clock() - time)
    
        o = Multi(count)
    
        time = os.clock()
    
        for i = 1, count do
            o.Value = i
            r = o:Result()
        end
    
        print("Finish for one object", os.clock() - time)
    
        time = os.clock()
    
        for i = 1, count do
            r = Multi(i):Result()
        end
    
        print("Finish for multi objects", os.clock() - time)
    end


    This is a simple test, there is a normal function Result, and a method function object:Result(), they do the same thing.

    And using 'MultiCount' to control the usage of the function (method) body, the function body is normal lua code too, as you see.

    A test function a() receive a count variable to control the repeat time. The first part for a() is normal lua code, just call the Result function, the second part, using one object call it's Result method, the last part is create one object each time and then call their Result method.

    For MultiCount = 100
    > MultiCount = 100
    > collectgarbage()
    > a(10)
    Finish for normal	0.00041199999998298
    Finish for one object	0.000419000000079
    Finish for multi objects	0.00057400000002872
    > a(100)
    Finish for normal	0.003039000000058
    Finish for one object	0.0025710000001027
    Finish for multi objects	0.0029170000000249
    > a(1000)
    Finish for normal	0.018779000000109
    Finish for one object	0.014499999999998
    Finish for multi objects	0.018570999999952
    > a(10000)
    Finish for normal	0.14042199999994
    Finish for one object	0.14425199999994
    Finish for multi objects	0.18008999999995
    > a(100000)
    Finish for normal	1.4045729999999
    Finish for one object	1.460615
    Finish for multi objects	1.827017


    For MultiCount = 1000

    > MultiCount = 1000
    > collectgarbage()
    > a(10)
    Finish for normal 0.002837999999997
    Finish for one object 0.0022279999999455
    Finish for multi objects 0.0023069999999734
    > a(100)
    Finish for normal 0.017513000000008
    Finish for one object 0.012967000000003
    Finish for multi objects 0.014123999999924
    > a(1000)
    Finish for normal 0.13638000000003
    Finish for one object 0.133734
    aFinish for multi objects 0.13705099999993
    > a(10000)
    Finish for normal 1.317129
    Finish for one object 1.321518
    Finish for multi objects 1.3520689999999


    It's interesting when repeat times is 10 - 1000, the method cost is lower than the normal function?that's because the api the method need is stored in the class's environment, and the access speed is a little quick than in _G.

    And above 10000, the method cost more than the normal function, there is one more function call when object find it's method, that's the cost the oop system must pay.

    The most cost for the oop system is in the object's creation, but for most development, the objects only will be created once.



    And about the memory usage.

    For a light-weighted oop system, class will fill it's method to their objects like :

    do
        -- a light-weighted class
        myclass = {}
    
        function myclass:methodA()
        end
    
        function createObject()
            local obj = {}
            for i, v in pairs(myclass) do
                obj[i] = v
            end
            return obj
        end
    
        -- we create 1000 object
        collectgarbage()
    
        collectgarbage('stop')
    
        memory = collectgarbage('count')
    
        for i = 1, 10000 do
            obj = createObject()
        end
    
        print(collectgarbage('count') - memory)
    
        collectgarbage('restart')
    end


    The result is 1015.625

    And for the IGAS's class
    require "igas"
    
    do
        class "MyObject"
            -- Method
            function Result(self)
            end
        endclass "MyObject"
    
        collectgarbage()
    
        collectgarbage('stop')
    
        memory = collectgarbage('count')
    
        for i = 1, 10000 do
            obj = MyObject()
        end
    
        print(collectgarbage('count') - memory)
    
        collectgarbage('restart')
    end


    The result is 625.

    Don't forget a table stored others should require some memory for it's indexes.
    Posted in: Libraries
  • 0

    posted a message on In-Game Addon System (IGAS)
    The class part would cost more memory than the pure oop system in lua, that's true, but not the cpu usage, and it would be easily to make classes then in the pure system if you want do something bigger.

    It's not just it's big, so it cost more cpu, I also test the IGAS_UI with raid, it's full of unitframes, buttons, and no 'script run too long error' happens(My laptop only 10-15 fps in raid).

    Although only one addon means nothing, but the cpu cost is only for system event handler, script event handler, hook ,slash commands, it's not hard to know which would cost too much to hit the limit.

    IGAS also provide a thread system for making a long time function. (The Sleep api also can be done in other libs, I don't think the script limit should be used to judge a system, there are plenty ways to solve it.)

    function DoSomeBig()
        while true do
            System.Threading.Sleep(1)  -- stop for 1 sec
        end
    end
    
    self:ThreadCall(DoSomeBig)       -- call as a thread.


    Classes almost are used to store the method (and other settings) for all objects, waiting the call, that's more like a storage.The interface would manager things, but with correct design, the cpu cost will be less then do the same thing in each objects.

    The main purpose for IGAS is to provide an inheritance system instead of the blizzard's xml system, so I can make frames just like what we do in the visual studio. you can find sample on IGAS's page.

    form = IGAS.System.Widget.Form("Test")
    
    form.Caption = "MyForm"


    That's why I need a more powerful oop than the default one. And with the power of the class system, it also can be used to do some addon works.

    IGAS is building on the pure lua 5.1, the core part can be used out of wow, I also used it in the Windows.

    Objects' method(property) would be called through IGAS's core part(just the object's metamethod __index, so one more function in chain), so there are a little more cost in it.
    Posted in: Libraries
  • 0

    posted a message on In-Game Addon System (IGAS)
    Always simple oop programs can be done in the structure languages with a little less code, and compare something with different contents has no meanings.

    Just like making a web project, why using jquery since I can do every js working myself with a little less coding than the jquery itself.

    Ouf is an good example for me to know which indicators are useful to bring in the default system, you may find similar things in it, but the core mechanism and layout's coding are quite different, I'll discuss it in a later document but not here.

    I don't think I can persuade somebody to change mind, I'm not good at speech, also not good at english. And I don't request everybody to go on with this lib, it's just a choice.
    Posted in: Libraries
  • 0

    posted a message on In-Game Addon System (IGAS)
    The main cause for using private environment is used to reduce lua closure, not only about separated from _G, you really don't understand the lua environment.

    The core part of IGAS is designed for pure lua 5.1, it didn't care what the wow changes(it won't go lua 5.2 since its secure system).

    What the widget-framework done is using a dynamic api fetching system, so it will automatically update when blizzard widget's api changes.

    The last part : action and unit frames, well, it needs people to update, I agree with that, but also to all other libs. And I don't see any possibility that I would abandon this lib, if I really have to, I also have people to continue it now.

    Lua lacks the real oop, so there were a lots of oop modules outside wow. What oop I mean is compare to things like VB.Net, C# and other modern languages (or like python), not that poorly one in lua if what you means. You can't measure what it can do just by watching the basic system.

    Reading code require a better editor and with correct code folding and other settings, and if you don't know much about the system, reading code always be a hard or impossible things. Many ace3 libs looks ugly for me too.

    I don't suggest anybody to read IGAS directly, many files had no meanings until they had been put together, and this lib is too large to be read with no purpose.

    I just suggest reading the RaidPanel or UnitFrame_Slim in IGAS_UI after you done the documents learning.
    Posted in: Libraries
  • 0

    posted a message on In-Game Addon System (IGAS)
    That's the different from IGAS to the common add-on development, you always run addons in global environment and I don't.

    If you pay attention, every file has a 'NewAddon("xxx")' on the top, it change the global environment to the addon self, you won't find any global variables defined to the _G.

    The addon environment mechanism is using to reduce lua closures and quick accessing, and the environment is shared between files(when I do this, there was no blizzard's share table mechanism and that one is too simple).

    For add-on development experience, I start addon working since wow is 1.0 version, also do the 'normal addon lua code' at the beginning. I don't care normal addon development, so my addons always are development-tools.

    I have an addon group in China now, and they need more than an widget-ui development lib.So I finished the action and unit frame system in last three month, made a demo add-on:IGAS_UI, it works fine, so I thought it's time to bring it out.

    Thx Dridzt, I'll go on with the documents. The class system is only the base part, there are more systems built on it.

    I know the code will be hard for people with only lua experience at the first time, but it's easy for people has experience with .Net and other oo languages.
    Posted in: Libraries
  • 0

    posted a message on In-Game Addon System (IGAS)
    It is always about how to think not only about how to code.
    Posted in: Libraries
  • 0

    posted a message on In-Game Addon System (IGAS)
    Some basic introduction will be throw to lib IGAS's forum if I have time.

    IF you has experience in oo coding, you may find many familiar things in this system.
    Posted in: Libraries
  • 0

    posted a message on In-Game Addon System (IGAS)
    Full name In-Game Addon System.This lib provide a full object-oriented system for lua, and with this system, plenty classes are bring in the wow to help addon development.

    Lib url : http://wow.curseforge.com/addons/igas/

    Also there some addons to show what this lib can do:

    Cube : this addon help debug and coding in wow's game enviroment.
    http://wow.curseforge.com/addons/igas-cube/

    IGAS has many common widget classes to create ui elements, and it's very simple to make new widget classes base on the IGAS's inherit system.

    IGAS_UI: this addon contains an action bar system, an unitframe system, a raid panel and etc, the code in it is simple.
    http://www.curse.com/addons/wow/igas_ui

    IGAS also has many secure widget classes to create secure unit elements, see the IGAS_UI, want add a portrait for the unit frames, just one line code.

    IGAS is a big project to be explain in one page. And later I will add a document-browser in the Cube, I thought a simple class example is good to go, the system is different from normal lua code.If you have Cube and with the newest IGAS lib, you can try it.

    class "BaseClass"    -- class definition started
        
        -- property definition
        property "Name" {
            Set = function (self, name)
                self._Name = name
                print("New name is", name)
            end, 
            Get = function (self)
                return self._Name
            end, 
            Type = System.String,  -- Type is used to check the property value, so no need do it self.
        }
        
        -- function with the name of the class is constructor, it receive self as the class's object, and other init parameters is passed in after self.
        function BaseClass(self, name)
            self._Name = type(name)=="string" and name or "Noname"
        end
    endclass "BaseClass"  -- finish class definition
    
    class "MyClass"
        inherit "BaseClass"   -- inherit all property, method, script handler and etc from the parent class
        
        -- function defined as global and not with name of the class is the method
        -- the method's first argument is self
        function PrintName(self)
            print("Self's name is", self.Name)
        end
    endclass "MyClass"
    
    obj = MyClass()
    obj:PrintName()   -- print "Self's name is Noname"
    
    obj.Name = "Test"  -- print "New name is Test"
    obj:PrintName()     -- print "Self's name is Test"


    IGAS also provide an enum system to control enumeration values, a struct system to control formatted tables, and an interface system to extend the class system.
    Posted in: Libraries
  • 0

    posted a message on Sushi-3.0
    IGAS (In-Game Addon System)
    This is a full object-oriented system?and now just in beta version, maybe can be released before mop.

    The system apply things like:
    Class
    Interface
    Struct
    Enum

    Class and interface make custom widget more simple and efficient.Here is a sample for class and interface.It make a button class type that can be changed to movable & resizable mode.

    Test sample pic: you can visit bbs.ngacn.cc first, then view these pics
    http://img.ngacn.cc/attachments/mon_201207/27/-76204_501217b7158fe.jpeg

    Code part:
    http://img.ngacn.cc/attachments/mon_201207/27/-76204_501217c14832a.jpeg
    IGAS:NewAddon "Test"  -- Create Addon Test and make env to the addon
    
    import "System.Widget"  -- import namespace System.Widget, 
                                      --which contains useful wow widgets and interfaces.
    
    class "MButton"               -- Start define MButton class
        inherit "NormalButton"  -- NormalButton is a custom button type
        extend "IFMovable" "IFResizable"   -- IFMovable apply the ability to into move mode
                                                       -- IFResizable apply the ability to into resize mode
    
        -- property definition, IFMovingGroup is difined in IFMovable, need override,
        -- to point which group the MButton's object in.
        property "IFMovingGroup" {
            Get = function(self) return "MButton" end,
        }
    
        property "IFResizingGroup" {
            Get = function(self) return "MButton" end,
        }
    
        -- the function with name as the class name, is the constructor
        function MButton(name, parent)
            local btn = Super(name, parent) -- Super is NormalButton here
    
            -- Setup
            btn.Style = "Classic"
            btn.Height = 26
            btn.Width = 60
            btn.Text = name
            btn:SetPoint("CENTER")
      
            return btn
        end
    endclass "MButton"     -- end the definition of MButton
    
    ----------------------------------
    -- Frame set part
    ----------------------------------
    f = Form("Test")        -- no need use local because this code is running in add-on env
                                  -- Form ,you know
    
    for i = 1, 10 do
        btn = MButton("Button_" .. i, f)
        if i%3 == 0 then btn.Visible = false end
    end
    
    ------------------------------------
    -- Turn move & resize mode on
    ------------------------------------
    IGAS.System.Widget.IFMovable._ModeOn("Mbutton")
    IGAS.System.Widget.IFResizable._ModeOn("Mbutton") 


    Well, it's hard to explain all in one pic.I try to make all code more readable.
    Posted in: Libraries
  • To post a comment, please or register a new account.