• You've discovered RedGuides, an EverQuest multi-boxing and scripting community 🧙‍♀️⚙️. We want you to play several EQ characters at once, come join us and say hello! 👋

  • A TLP without truebox has thawed (Very Vanilla ready)
    Frostreaver

Lua - LUA, TLOs, and final Parens

ButtKoWitz

Member
Joined
Mar 23, 2023
RedCents
342¢
New to Lua and MQ so be patient :)...

I'm a little confused about when to include, or not, the final parenthesis when building an mq.TLO... call. The Lua Scripting in MacroQuest guide offers some info towards this, and definitely says "append () to the end to finally bring the result into lua"
(specifically here: https://docs.macroquest.org/lua/#tlo-bindings ). But where I'm confusing myself is when I'm looking over the example Lua scripts I see sometimes the mq.TLO... calls have extra ending parens, and sometimes not (most times not).

Two example scripts that come with default install of MQ) that have me confused are:
PackageMan.Lua ...
[CODE title="Line 28"]local cliInstallPath = mq.TLO.Lua.Dir('modules')() .. '\\luarocks'[/CODE]
Are the final parens necessary, as ...Dir('modules') seems to me to be the closing set.

The other confusing call is:
autoassist.Lua
[CODE title="Line 5"]local groupAssist = function () return mq.TLO.Me.GroupAssistTarget end -- Note the lack of parentheses here[/CODE]
Umm o.k. But why am I'm noting the "lack of parens here"?

Thanks!
 
so the ending parens turns the Lua userdata into the datatype you would expect, like a string, or int, or bool. so when you need those things youd want to use parens, or else its gonna be a Lua userdata, which you cant really do anything with as such.

the 2nd example dont have it, because its a condition, so the type it returns is not important, either you have a groupassist or you dont.

thats atleast how i understand it, i am most likely 149% wrong
 
so the ending parens turns the lua userdata into the datatype you would expect, like a string, or int, or bool. so when you need those things youd want to use parens, or else its gonna be a lua userdata, which you cant really do anything with as such.

the 2nd example dont have it, because its a condition, so the type it returns is not important, either you have a groupassist or you dont.

thats atleast how i understand it, i am most likely 149% wrong

In the second case, you want the object, no the value, so that you can pull other values from it later, I presume. Hard to tell from just that one line. Context is important.
 
if you want a Lua data type, you need trailing empty parens.
if you leave them off you get userdata which you can continue to use later

Code:
local groupAssist = function () return mq.TLO.Me.GroupAssistTarget end -- Note the lack of parentheses here

print(groupAssist.ID())

..
or just
Code:
local groupAssist = mq.TLO.Me.GroupAssistTarget
print(groupAssist.ID())
 
if you want a lua data type, you need trailing empty parens.
if you leave them off you get userdata which you can continue to use later

Code:
local groupAssist = function () return mq.TLO.Me.GroupAssistTarget end -- Note the lack of parentheses here

print(groupAssist.ID())

..
or just
Code:
local groupAssist = mq.TLO.Me.GroupAssistTarget
print(groupAssist.ID())
hmm what is the purpose of running a function there? would it return false if there was no groupassist set?
 
Lua - LUA, TLOs, and final Parens

Users who are viewing this thread

Back
Top
Cart