View Single Post
08-29-11, 10:30 PM   #1
kurapica.igas
A Chromatic Dragonspawn
Join Date: Aug 2011
Posts: 152
Object-Oriented System for lua

Well, I want to introduce my lib addon 'IGAS'. Although it's just in beta, I thought it's time to bring it in.

In this addon, I built a object-oriented system for lua. Here is a sample code running outside wow.

Code:
require "oop"

IGAS:NewAddon("MyTestAddon") -- keywords like 'class' only working under addon's enviroment

class "Test"  -- begin class definition
	inherit "System.Object"    -- inherit class, System.Object is the base class for others.

	script "OnNameChanged"  -- like "OnClick" for blz's button, the script handler declaration

        -- property definition
	property "Name" {
		Get = function(self)
			return self.__Name
		end,
		Set = function(self, name)
			self.__Name = name
			self:Fire("OnNameChanged", name)
		end,
		Type = String,  -- the type's value can be class, struct, enum or nil, used for validation.
	}

        -- Global function is the class's method
	function PrintName(self)
		print(self.__Name)
	end

        -- the function with the class's name is the constructor
	function Test(name)
		local obj = System.Object()

		obj.__Name = name

		return obj
	end
endclass "Test"  -- end class definition
Here is a test result pic:
Click image for larger version

Name:	testIGAS.jpg
Views:	1066
Size:	70.4 KB
ID:	6467

Some information about this system:
1. three base data structure type
class
enum
struct

2. Now base structs(WOW's structs not included) stored in global namespace:
System.Boolean
System.String
System.Number
System.Function
System.Table
System.Userdata
System.Thread
System.Any
System.LocaleString

2. Now classes stored in global namespace:
System.Object
System.Threading.Thread
System.Addon
System.Addon.Module
System.Locale
System.Logger

-- For wow
System.Widget.UIObject
System.Widget.VirtualUIObject

System.Widget.AnimationGroup
System.Widget.Animation
System.Widget.Translation
System.Widget.Rotation
System.Widget.Scale
System.Widget.Alpha

System.Widget.Font
System.Widget.Region
System.Widget.LayeredRegion
System.Widget.Frame
System.Widget.Texture
System.Widget.FontString
System.Widget.FontFrame
System.Widget.Button
System.Widget.Cooldown
System.Widget.ColorSelect
System.Widget.EditBox
System.Widget.GameTooltip
System.Widge*****ssageFrame
System.Widget.Minimap
System.Widget.Model
System.Widget.ScrollFrame
System.Widget.ScrollingMessageFrame
System.Widget.SimpleHTML
System.Widget.Slider
System.Widget.StatusBar
System.Widget.CheckButton
System.Widget.PlayerModel
System.Widget.DressUpModel
System.Widget.TabardModel
System.Widget.ArchaeologyDigSiteFrame
System.Widget.QuestPOIFrame
System.Widget.MovieFrame

System.Widget.NormalButton
System.Widget.Timer
System.Widget.ColorPicker
System.Widget.DropDownList
System.Widget.ScrollBar
System.Widget.ScrollForm
System.Widget.Form
System.Widget.GroupBox
System.Widget.List
System.Widget.ComboBox
System.Widget.SingleTextBox
System.Widget.MultiLineTextBox
System.Widget.TreeView
System.Widget.TabGroup
System.Widget.CheckBox
System.Widget.PopupDialog
System.Widget.MinimapIcon
System.Widget.OptionSlider
System.Widget.DataGrid

For the first step, go here for a look:
http://code.google.com/p/igas/wiki/IGAS_OOP

If you like it, I may find a way to post more information about this in the future time, Now I'm working on a CodeEditor to fix my IGAS_Studio(The in-game IDE), just a little busy.

Last edited by kurapica.igas : 08-29-11 at 10:34 PM.
  Reply With Quote