• 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

Problem - Lua Object Type returns

Coldblooded

Zero Fuchs Given
Creator
Joined
Mar 23, 2019
RedCents
8,961¢
Pronouns
He/Him
I'm in the process of porting a macro over to Lua and I've run up against a lot of woes in working with return types from TLOs.

For all the methods I've been working with, it looks like those that would normally return "some value" or NULL - don't return an object type nil, but rather an object of type userdata. You have to pass the returned userdata to the global tostring() method and compare the value against a static string "null".

In Lua "truthiness", false == false, nil == false, and everything else is true...

So in this codeblock, regardless of what is returned (either the spell or userdata containing "null") it equates to true and we always see "Death Punch!"
C-like:
if mq.TLO.Me.Spell("Death-Fu Death Punch") then
    print("Death Punch!")
else
    print("Death Block!")
end
 
Some methods, do in fact return correct types - so for example

mq.TLO.Me.PctExp()

Is a type number
print(type(mq.TLO.Me.PctExp())

But then
mq.TLO.Me.Skill("Abjuration")
is type userdata.

If you wanted to evaluate this as a number
tonumber(mq.TLO.Me.Skill("Abjuration"))

Will return nil because the tonumber method has not been coded on the userdata metaobject in question.

So, to evaluate this as a number, you have to first convert it to a string, then a number like so...
tonumber(tostring(mq.TLO.Me.Skill("Abjuration")))
 
If you provide an "index" or parameter to the TLO like Skill("Abjuration") then you need to call the call operator to get the actual value. since Skill("Abjuration") returns the mq datatype Spell, which is a user data. if you want to evaluate it to a Lua type then you need to do something like Skill("Abjuration")() which i believe is doing the ToString but it might be something else, I don't recall. dannuic knows best.
 
If you provide an "index" or parameter to the TLO like Skill("Abjuration") then you need to call the call operator to get the actual value. since Skill("Abjuration") returns the mq datatype Spell, which is a user data. if you want to evaluate it to a lua type then you need to do something like Skill("Abjuration")() which i believe is doing the ToString but it might be something else, I don't recall. dannuic knows best.


You are correct! Methods that take arguments need an additional () on the end to return equivalent data types! Thank you, this saves a lot of headaches!

INI:
local mq = require('mq')
local Me = mq.TLO.Me

print(Me.CombatAbility("Guard of Piety"))
print(type(Me.CombatAbility("Guard of Piety")))
print(type(Me.CombatAbility("Guard of Piety")()))


1620779609016.png
 
Last edited:
yeah, I had to have an explicit transform from userdata, so I used the extra call parens. I waffled between that and some specific member, but I decided that I couldn't guarantee that any specific transform "member" wouldn't collide with an mq2 datatype member, so I opted for the parens. It doesn't actually use ToString, it grabs the type from the VarPtr variant and puts that on the Lua stack (allowing sol2 to do its normal primitive type conversions).
 
Problem - Lua Object Type returns

Users who are viewing this thread

Back
Top
Cart