Thread Tools Display Modes
12-28-05, 06:58 PM   #1
instant
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Oct 2005
Posts: 17
HOW: OnLoad / OnEvent without XML

How can I make a .LUA script that does OnLoad and OnEvent without having to use those pesky .XML files...

(And not using ace either, i dont want that as a dependency for that this addon should do... Its _really_ simple.. but it needs to be loaded first..)
  Reply With Quote
12-28-05, 07:45 PM   #2
instant
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Oct 2005
Posts: 17
Argh...

=)

Thanks anyway
  Reply With Quote
12-29-05, 10:56 AM   #3
sacha
An Aku'mai Servant
 
sacha's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2005
Posts: 38
An ugly and hackish way of getting around the XML dependancy for events would be to hook an existing function that is already called via events, eg. hooking Minimap_OnEvent() etc. However I would still recommend using your own XML for event driven functions.

IF all you want is to get a function to be called as an OnLoad tag would, try putting the lua filename in your toc as follows:

Code:
## Interface: 1900
## Title: MyAddonTitle
## Author: MyName
MyAddonLuaFile.lua
Then, in your 'MyAddonLuaFile.lua' file:
Code:
MyAddonTitle_IsActive = nil;

function MyAddonTitle_OnLoad()

   -- Init code
   MyAddonTitle_IsActive = 1;

   -- You can also create hooks as decribed 
   -- above instead of registering for events 
   -- There are several ways of doing this  
   MyAddonTitle_Original_Minimap_OnEvent = Minimap_OnEvent;
   function Minimap_OnEvent()
      
      -- My addon's event driven code

      -- Call the hooked function
      MyAddonTitle_Original_Minimap_OnEvent();
   end

end

-- Now to call the 'MyAddonTitle_OnLoad()' function
MyAddonTitle_OnLoad();

Last edited by sacha : 12-29-05 at 06:37 PM.
  Reply With Quote
12-29-05, 11:48 PM   #4
Gazmik
A Cobalt Mageweaver
 
Gazmik's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2005
Posts: 245
Come 1.10 this will change: re slouken's 1.10 sneak peek - Dynamic Frames thread on the Blizz boards, we'll be able to create frames from lua. (And once we've created a frame, we can register OnEvent and other handlers for it.)

Will be nice to get rid of the otherwise superfluous XML in some of my addons...
__________________
Gazmik Fizzwidget's UI Addons: www.fizzwidget.com
  Reply With Quote
01-05-06, 03:47 AM   #5
xmlover
A Fallenroot Satyr
Join Date: Oct 2005
Posts: 25
Originally Posted by instant
How can I make a .LUA script that does OnLoad and OnEvent without having to use those pesky .XML files...

(And not using ace either, i dont want that as a dependency for that this addon should do... Its _really_ simple.. but it needs to be loaded first..)
before 1.10 is release

one lua for all is just a dream

it only happens in a hook Addon

i only know this

Code:
Frame:SetScript("handler", "function") 

if ( YourFrame:HasScript( "OnClick" ) then
     YourFrame:SetScript( "OnClick", "YourOnClickScript" )
end
  Reply With Quote
01-05-06, 03:48 AM   #6
xmlover
A Fallenroot Satyr
Join Date: Oct 2005
Posts: 25
Originally Posted by Gazmik
Come 1.10 this will change: re slouken's 1.10 sneak peek - Dynamic Frames thread on the Blizz boards, we'll be able to create frames from lua. (And once we've created a frame, we can register OnEvent and other handlers for it.)

Will be nice to get rid of the otherwise superfluous XML in some of my addons...
is that mean you will do a ObjectCreate Engine in 1.10 for your addons,Gazmik?

'cos the object created from the offical API is empty with all propeties

there're lots of things to do
  Reply With Quote
03-29-06, 09:30 PM   #7
edv
A Murloc Raider
Join Date: Feb 2006
Posts: 2
I'm just starting with lua (and programming in general) so I've probably misunderstood something big. Below is the code I was able to come up with, but it simply doesn't work. Could anyone tell me what I'm doing wrong?

Code:
local myframe = CreateFrame("Frame", "myframe", UIParent);
myframe:SetScript("OnLoad", function() myframe_OnLoad() end)

function myframe_OnLoad()
	ChatFrame1:AddMessage("myframe loaded");
end
  Reply With Quote
03-29-06, 10:40 PM   #8
Gello
A Molten Giant
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 521
I'm pretty sure the OnLoad has come and gone by the time CreateFrame is done.

Try this:

function myframe_OnLoad()
ChatFrame1:AddMessage("myframe loaded");
end

local myframe = CreateFrame("Frame", "myframe", UIParent);
myframe:SetScript("OnEvent", function() myframe_OnLoad() end)
myframe:RegisterEvent("PLAYER_LOGIN")
  Reply With Quote
03-30-06, 05:17 AM   #9
edv
A Murloc Raider
Join Date: Feb 2006
Posts: 2
Thanks, that works great!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » HOW: OnLoad / OnEvent without XML

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off