ebLibs

The ebLibs is a base libaray for any RoM addons.
Its contains a event, memory and object model.

Programmers from Flash AS3 maybe remember some functions ;)

The Library is written in a OOP-style. So exists classes and inheritances. The class concept is used from JavaScript and Flash10.

The package realize the non-linear event orientent module programming. With this package is it possible, to program in multi thread's and time based called functions.
In primary react the package on the users actions in the game. So is it possible to create any addon based on this libraray.
The addon programmer dosen't need to think about variable loading or memory handling. He write his addon in a hierical class structure und use events for communication between the modules.
The events will be created in runtime, so the addon programmer can define his own event names. So is it also possible to create a event-api for communication between addons.

This library DON'T override or change any ingame included functions. It is impossible to write addons to hack or crack other player clients with this libraray.
The library USE only the function API from RoM. If a programmer want to communicate with other clients which used the same addon(eg. WoW's carbonite), so he has to do it with RoM-API-function.

To create a object call the class(it is a function ;) directly:
local obj = ebObject();
obj.print("Hello World);

If you like to extend the library, send me your changes as patch-file(linux's diff text) over http://rom.curse.com/members/kique.aspx

(Example application on the end of this file.)

Changelog:
1.0.2.0 beta - adding ebSkill
1.0.1.0 beta - new version format (major.minor.addon.bugfix adding ebUnit and ebString; several changes
1.0 beta - first beta realease

Classtree:

ebObject
 |
 +-- ebArray
 |
 +-- ebEventDispatcheer
 |    |
 |    +-- [final|static] ebSystem
 |    |
 |    +-- [final|static] ebEventHandler
 |    |
 |    +-- ebApplication
 |    |
 |    +-- ebUnit
 |    |
 |    +-- ebSkill
 |
 +-- ebEvent
 |
 +-- ebString

global objects:
 
eb - Class and memory holder.
ebLibs_MEM - Memoryblock (normal access over eb.mem
eb.mem - Memoryblock (ready after event ONINIT)
eb.system - Systemobject (see ebSystem)
eb.event - System event object (see ebEventHandler)

Reference:

ebObject - base class
    Attribute:
        id - unique object id
        prototype - reference to the class (for checks: obj.prototype == ebObject   or for cloneing: local clone = this.prototype(); clone.value = this.value
    Functions:
        toString():string - convert object to string
        ebObject() - Constructor
        print(msg) - mixin from ebSystem

ebArray([...]) - a Array implementation
    Attributes:
        [protected] data - the lua table for the data
        [readonly] length - length of the array
    Functions:
        push(item):number - add the item to the array and returns the index number
        item(id) - return the item at id position or nil if id not exists
        splice(id, len[, item[,...]]) - remove len items at id position and insert the item(s)
        pop() - remove and return the last item
        unpack() - lua's unpack for tables
        indexOf(object) - return the index of object or -1 of object not in index
        destroy() - garbage collector. Note: this function is prepeared for sub classes, to remove event bindings or other links.
    Example:
        local ar = ebArray("Hello", "World");
        eb.system.print(ar.item(0)); -- Hello
        eb.system.print(ar.item(1)); -- World

ebSystem - provides univeral system functions
    Attributes:
        [ro] version - versions string
        [ro] frame - ebLibs's frame
        [ro] isInit = true, if system ready and memory loaded.
    Events:
        ONINIT - is dispatching after loading the memory block
    Functions:
        print(msg) - print the msg in the default chat
        [internal] onLoad - interal initialize handling
        [protected] onVariablesLoaded(event) - callback function for the game's VARIABLES_LOADED event
        save - save the memory block
    Note:
        This class is automaicaly create by the system and accessable under eb.system

ebEventDispatcher - event dispatching, adding, removing and receiving functions
    Attribute:
        [protected] list - registered events
        [protected] queue - event queue for the frame
    Functions:
        dispatchEvent(event:ebEvent) - send the event at the next frame
        [internal] onEnterFrame - called by each new frame from system event handler
        [internal] checkFor
        addEventListener(eventName:string, callback:reference) - add the callback reference to the eventName's list
        removeEventListener(eventName:string, callback:reference) - add the callback reference from the eventName's list
    Note:
        A reference can only one time be added to the eventName's list. The second (or more) add's of the same reference to the same eventName will be ignored.
        Don't forget to remove the ebEventDispatcher object from eb.event.eventObjectList if the object not more needed.
        
ebEvent(event[,...]) - The event object from type event
    Attributes:
        [ro] type - event type (first argument of constructor)
        [ro] content - arguments of event creatings (rest arguments of constructor)
        [ro] target - object, which send this event
    Functions:
        clone():ebEvent - clone the event
    Example:
        function myTest()
            local this = ebObject();
            
            --[[
                event receiver
            --]]
            this.onTestEvent = function(event)
                this.print(event.content[1]);
            end
            
            return this;
        end

        local disp = ebEventDispatcher();
        local test = myTest();

        -- register for event
        disp.addEventListener("ONTEST";, test.onTestEvent

        -- send event
        disp.dispatchEvent(ebEvent("ONTEST";, "Hello World"));
        -- Output in next frame: Hello World
        
ebEventHandler
    Attributes:
        eventObjectList - system wide event dispatcher list
    Functions:
        [internal] onEvent - connection function to the game API
    Note:
        This class is a singelton class and cant instanciate multiple time.
        You can access the object over eb.event to add listener.
    Example:
        -- this example wrote "tick...tick..." each frame in the chat
    
        function myFrameTicker()
            local this = ebEventDispatcher();
            
            this.myFrameTicker_onEnterFrame = this.onEnterFrame
            this.onEnterFrame = function()
                this.myFrameTicker_onEnterFrame();
                
                this.print("tick...tick...");
            end
            
            return this;
        end

        local t = myFrameTicker();

    Example2:
        -- other way, same effect
        function myFrameTicker()
            local this = ebObject();
            
            this.onTick = function(event)
                this.print("tick...tick...");
            end
            
            return this;
        end
        
        local t = myFrameTicker();
        eb.event.addEventListener("ENTER_FRAME";, t.onTick);
        
ebApplication:
    Attributes:
        mem - memory block for the application
        name - name of the application (is the name of the main frame)
        frame - reference from the main frame
    Functions:
        [internal] init - initialize the memory block
        run - this function contains the application (has to be ovveride in sub classes)
        toString - convert the object to string
        save - reference to eb.system.save save the memory block
        
ebUnit: - Information about a unit
    Attributes:
        [ro] unit - string of me type (player, target, targettarget, etc)
        [ro] maxMana - units max. mana
        [ro] mana - units actual mana
        [ro] maxRage - units max. rage
        [ro] rage - units actual rage
        [ro] maxFocus - units max. focus
        [ro] focus - units actual focus
        [ro] maxEnergy - units max. energy
        [ro] energy - units actual energy
        [ro] maxLife - units max. life
        [ro] life - units actual life
        [ro] name - name of this unit
        [ro] class - table with prim. and secon. class  (class[1] = primary class, class[2] = secondary class)
        [ro] target - ebUnit-object of target (to get targettarget...ebUnit("player").target.target ebString of target's name, if target already in the unitlist since first unit
        [internal] blocklist - name of unit in list to stop self referer
    Functions:
        refresh() - actualize all values
        [internal] getClass():table - refresh and return unit's classes
        [internal] getMana():table - refresh and return unit's mana/rage/energy/focus
        [internal] getLife():table - refresh and return unit's life
        [internal] getName():string - refresh and return unit's name
        [internal] getTarget():ebUnit or ebString - refresh and return unit's target
        toString() - convert to string
        [internal] removeTarget()
        getUnit(name):ebUnit - get a unit object of unit with name, if it in the target-list
        getLastUnit():ebUnit - get last unit object in target list
        [internal] bindEvents() - bind events from event system
        destroy() - remove all event bindings and the target list (manual garbage collector)
    Events:
        ONCHANGE - send this event, if the unit or a unit in the targetlist changed
                   content: table with type and actual value (content[1] = { type="life|mana|class", now="value|class table", unit=ebUnit-object }
    Note:
        Attantion: Run destroy() BEFORE you delete the unit object. If you forget the call of destroy(), then will the object be holded in the system event list.

ebSkill
    Attributes:
        [internal] data - skilldata
    Functions:
        [internal] scanBook - load the skill data from the skill book
        refresh - same of scanBook
        this.getSkillById(id):table - return the skillinfo for SkilID
                                           table syntax: {["id"]=SkillID, ["name"]=SkillName, ["parseName"]=SkillNameFromParseSkillLink, ["icon"]=iconimagepath, ["link"]=SkillHyperlink}
        search(spell) - search for a skill. spell can be a link, name, parsed name or id.
        cast(id):boolean, colldown, fullCooldown - Casting spell/skill. if return false, then is cooldown time and not casted.
    Note:
        This object is accessable over eb.skill and is a singelton object. A 2. create has no effect.
        
        

        
        
        

        
Example application (zTest):

zTest.toc
----------
## Title: zTest
## Version: 1.0
zTest.xml
zTest.lua

zTest.xml
----------
<Ui xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
    <Script file="zTest.lua"></Script>
    <Frame name="zTest" parent="UIParent">
        <Scripts>
            <OnLoad>
                zTest_onLoad(this);
            </OnLoad>
        </Scripts>
    </Frame>
</Ui>

zTest.lua
----------
assert(ebLibs, "Dependency ebLibs not loaded!");

function zTest_onLoad(frame)

    function zTest(frame)
        local this = ebApplication(frame);
        
        this.run = function()
            this.print("zTest initialized. My Reference="..this.toString());
        
            -- Loading of Values
            local runCount = this.mem.runCount
            if runCount == nil then runCount = 0; end
            runCount = runCount + 1;
            this.print("zTest runs now "..runCount.." times.");
            
            -- Saving of Values
            this.mem.runCount = runCount;
            this.save();
        end
        
        return this;
    end

    local app = zTest(frame);
    eb.system.addEventListener("ONINIT";, app.init
    _G.zTestApp = app; -- optional
end

You must login to post a comment. Don't have an account? Register to get one!

Facts

Date created
11 Jul 2009
Category
Last update
12 Jul 2009
Development stage
Beta
License
GNU General Public License version 3 (GPLv3)
Curse link
ebLibs
Recent files

Authors