Thread Tools Display Modes
09-26-13, 05:56 PM   #1
bsmorgan
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 219
Explanation of Lua Syntax needed

Can someone please explain what the "[[" and "]]" in the following code does. Notepad++ seems to know something is afoot as the code is syntax colored red.

Code:
-- 1) Rapid movement or movement off the window breaks the Blizzard code.  
--    We use a sensible timer to fix this - popupNaziSnippet
local popupNaziSnippet = [[
	local flag = self:IsUnderMouse(true)
	if (flag) then
		local queued = control:SetTimer(1, "hoverCheck")
	else
		local anchorButton = self:GetFrameRef("anchorButton")
		x, y = anchorButton:GetMousePosition()
		if (x and y) then
			local queued = control:SetTimer(1, "hoverCheck")
		else
			self:Hide()
		end
	end
]]
  Reply With Quote
09-26-13, 06:10 PM   #2
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
popupNaziSnippet is defined as a string to be later executed by loadstring
http://www.lua.org/pil/2.4.html
http://www.lua.org/pil/8.html
  Reply With Quote
09-26-13, 08:05 PM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
[[ ]] is for literal strings. They can be used in loadstring, you can also include line breaks and quotes in them. Some characters, such as a backslash, do not need to be escaped as well.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
09-27-13, 09:03 AM   #4
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
Using loadstring() to execute functions is an entirely different topic. Most cases it's not needed. So shed some light if you wanna use it like this, so we can evaluate how necessary it is!
__________________
Profile: Curse | Wowhead
  Reply With Quote
09-27-13, 02:51 PM   #5
bsmorgan
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 219
The snippet in the OP is from AutoBar. I'm trying to fix an annoying bug. Popups that are supposed to pop up when they are moused over and pop down when the mouse leaves sometimes stay popped up. This snippet is part of code that is supposed to force them down after a time interval, but it doesn't appear to work.

Its hard to fix something when you don't understand it! I started looking at the code and found this "literal string" construct that I'd never seen before. I now find it odd that I can't find "loadstring" anywhere in the addon.

Thanks for the insight. I'll see if this new knowledge will get me any further along.
  Reply With Quote
09-27-13, 03:18 PM   #6
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
There's a good possibility it's not loadstring() ed.

Snippets are typical for use in Secure Templates as well.
Edit: That is to say it may be loaded in a :Execute :SetAttribute :WrapScript etc call.

Last edited by Dridzt : 09-27-13 at 03:22 PM.
  Reply With Quote
09-27-13, 03:27 PM   #7
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
The use of the word "snippet" in the variable name along with the use of control and GetFrameRef in the code suggests that it is part of a secure object and the addon would not directly execute it via loadstring.

Edit: Dridzt beat me to it, wow I type slow.
  Reply With Quote
09-28-13, 07:46 PM   #8
bsmorgan
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 219
Can I put a "DEFAULT_CHAT_FRAME:AddMessage(msg);" into one of these literal strings for debugging purposes?
  Reply With Quote
09-28-13, 08:17 PM   #9
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Yes, you can. Btw DEFAULT_CHAT_FRAME:AddMessage(msg) is just the same as print(msg)
  Reply With Quote
09-29-13, 04:45 AM   #10
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
Actually print will also take in more arguments and join them with spaces, while AddMessage only takes one argument, the rest are for coloring, so two reasons to use print; shorter to write and prints all the arguments!
__________________
Profile: Curse | Wowhead
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Explanation of Lua Syntax needed


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