What "SetPtr" and "GetPtr" LM_Message's Methods stand for?

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
Rai López
Posts: 2244
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

What "SetPtr" and "GetPtr" LM_Message's Methods stand for?

Post by Rai López »

Hi, that's all. While the other LM_Message methods seem to be self explanatory enough, I don't get to know where SetPtr and GetPtr treat to point here. I've seen "Ptr" as an abbreviation of "Pointer" when reading about other languages, but I don't think it's a common term when it comes to Lua scripting level, so... any idea about when I could need to use e. g. "SetPtr(key, value)" instead of the normal "Set(key, value)"? I'm practically starting to deal with ScriptData() and I basically want to make sure I don't realize too late I missed what could have been a useful functionality or something just for not to ask...
Last edited by Rai López on Tue Feb 07, 2023 7:17 pm, edited 1 time in total.
...
User avatar
hayasidist
Posts: 3532
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: What "SetPtr" and "GetPtr" stand for?

Post by hayasidist »

Hmm ... never had any reason to look into those! Until now...

This is the code:

Code: Select all

		ScriptInfo:Set("MyScriptID_Int Value", 42)
		ScriptInfo:Set("MyScriptID_Bool Value", true)

		local v = LM.Vector2:new_local()
		v:Set(5.6, 7.8)
		ScriptInfo:Set("MyScriptID_Saved Vector2", v)

		local v = LM.Vector3:new_local()
		v:Set(3.4, 5.6, 7.8)
		ScriptInfo:Set("MyScriptID_Saved Vector3", v)

		ScriptInfo:SetPtr("P_MyScriptID_Ptr1", 123.4) 
		ScriptInfo:SetPtr("P_MyScriptID_Ptr2", true)
		ScriptInfo:SetPtr("P_MyScriptID_Ptr3", 16)


and this is what is saved in the moho file:

Code: Select all

"script_data":{"MyScriptID_Int Value":42.0,"MyScriptID_Bool Value":true,"MyScriptID_Saved Vector2":"5.600000 7.800000","MyScriptID_Saved Vector3":"3.400000 5.600000 7.800000","P_MyScriptID_Ptr1":0,"P_MyScriptID_Ptr2":0,"P_MyScriptID_Ptr3":0},
IOW the value set in a SetPtr isn't carried over to the file (which isn't surprising as it's labelled "void" in the documentation)... so I can only assume that it's useful in other uses of LM_Message (and not in ScriptData)?!
User avatar
Rai López
Posts: 2244
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Re: What "SetPtr" and "GetPtr" stand for?

Post by Rai López »

Thank you, Paul! So, out of the blue, one could think they may be intended to be used as some kind of temporary data store or something, or to send and receive data/messages that doesn't need to be recorded, e. g. between dialogs? But that wouldn't yet explain why the key is still stored along the layer, but not its value...

So, on second thoughts, couldn't it be instead simply a way to let you "initialize" a key just to ensure it already exists when you need to fill it with a value afterwards? I mean, in the same way you sometimes initialize a variable in Lua that you are going to fill/use later, plus that would make "Pointer" as a name to start making some kind of sense, isn't? Even thought I'm not totally sure yet what advantages it could have in comparison with using the other Methods...
...
User avatar
hayasidist
Posts: 3532
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: What "SetPtr" and "GetPtr" stand for?

Post by hayasidist »

LM_Message is used in other places -- and, guessing, perhaps internally to moho core -- such as feeding LM_SimpleDialog:HandleMessage(msg) ... i.e. msg comes from the LM_Message.fWhat ?? So these might not have meaningful use in Lua??????

[Again in the fantasy land that is my guesswork, I could imagine that metadata (and its successor, ScriptData) was piggybacked on a service (i.e. LM_Message) that **might** be at the heart of the functionality of Load/Save Prefs, except that Prefs are in user.settings and metadata / ScriptData is in the .moho ... and some of the stuff that is in LM_Message isn't relevant to ScriptData... but, like I say, no more than guesswork...]
User avatar
Rai López
Posts: 2244
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Re: What "SetPtr" and "GetPtr" LM_Message's Methods stand for?

Post by Rai López »

It well could be, it well could be... but it's kind of weird they end up exposing a method by mistake, isn't? I mean, I can't recall other cases when this has happened (although I'm not saying there couldn't be any). OTOH, what I do recall are cases where a method is supposed to return something but it returns void/none for whatever reason, like in the known LM_ImageTextList:SetSelItem() case, so maybe the method is exposed there for a reason, but somehow defective, only that in this case it's not easy to deduce its theoretical functionality due to there is also the handicap of not having anything else called "Ptr" or similar along all the scripting interface, so who knows...
...
User avatar
synthsin75
Posts: 9981
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: What "SetPtr" and "GetPtr" LM_Message's Methods stand for?

Post by synthsin75 »

I've always assumed it was just some exposed bit about the memory pointer of the message. Scripting wouldn't have much use for it, but might be necessary for the C+ binding.
User avatar
Rai López
Posts: 2244
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Re: What "SetPtr" and "GetPtr" LM_Message's Methods stand for?

Post by Rai López »

Well, at least that would mean I'm not missing anything potentially useful, that is what actually worried to me in first place... Thank you both, as always, for sharing your thoughts!
...
Post Reply