* Strange characters in LUA strings

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
Post Reply
avatar
TSG
Gold
Posts: 21
Joined: 07 Sep 2011 11:52
Family Historian: V6
Contact:

Strange characters in LUA strings

Post by TSG » 21 Jan 2012 08:21

This maybe a LUA bug rather than FH but if I do:

fhSetValueAsText(objFILE, 'C:UsersTestPicturesbag.jpg')

LUA sets the objFILE value to:

C:UsersTestPictures[?]ag.jpg

(where ? is a strange character rendered as a black box with a circle in it)

This can be seen in the debug variables window and is also the value put into the multimedia record in FH.

ID:5836

avatar
TSG
Gold
Posts: 21
Joined: 07 Sep 2011 11:52
Family Historian: V6
Contact:

Strange characters in LUA strings

Post by TSG » 21 Jan 2012 08:22

PS: I have only noticed this since 5.0.0.5. I *believe* it was working OK before but cannot guarantee it.

User avatar
SimonOrde
Program Designer
Posts: 352
Joined: 18 Nov 2002 10:20
Family Historian: V7
Location: Calico Pie

Strange characters in LUA strings

Post by SimonOrde » 21 Jan 2012 10:13

This isn't a bug - it's a feature of Lua. Within Lua, the backslash character '' has a special role in strings (as it does in other programming languages like C and C++). For example, 'n' means the newline character and 't' means a tab character. If you want to put a backslash into a string, you have to double it up to remove its special meaning. i.e. the line you needed was this:

fhSetValueAsText(objFILE, 'C:\Users\Test\Pictures\bag.jpg')

If you use that, the correct value 'C:UsersTestPicturesbag.jpg' will be inserted.

In case anyone reading this doesn't know what a 'string' is, incidentally, it means text in quotes.

User avatar
Jane
Site Admin
Posts: 8440
Joined: 01 Nov 2002 15:00
Family Historian: V7
Location: Somerset, England
Contact:

Strange characters in LUA strings

Post by Jane » 21 Jan 2012 11:32

Just to add to this, the escaping of the is only needed if you are entering the string directly in the source code, if you are prompting for a file name or obtaining it from iup.getfile or similar it can be entered as normal.

This is detailed on the Lua Quickstart page in the plugin help.
Jane
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."

Post Reply