[08 Feb 2008] Problem inspecting variables

Contains all messages from the Hollywood mailing list between 01/2006 and 08/2012
Locked
User avatar
Allanon
Posts: 742
Joined: Sun Feb 14, 2010 7:53 pm
Location: Italy
Contact:

[08 Feb 2008] Problem inspecting variables

Post by Allanon »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Fri, 08 Feb 2008 14:20:53 -0000

Hello, I've a problem inspecting table's elements, I'm not able to check if they exists or not.

For example I have this table:

Code: Select all

mytable = { }
I can check if the table exists comparing the table against <nil>, for this purpose I have a simple function that do the work:

Code: Select all

Function IsNil(value)
     If GetType(value) = #NIL Then Return(1) Else Return(0)
EndFunction
But if I want to check an element inside the table the procedure fails, so if I have:

Code: Select all

mytable = { name = "Fabio" }
NPrint(IsNil(mytable.name))               ; will print 0
NPrint(IsNil(mytable.surname))          ; will raise the error <table field "surname" not initialized!
I'm not able to solve this problem because I need to parse a table with various elements, if they exist I set them, if they not exist I have to get some standard values... in LUA every unset variables are <nil> so this check is very easy. Anyone knows how can I do this job?

Regards
----------------------------
[Allanon] Fabio Falcucci | GitHub (leaving) | Gitea (my new house) | My Patreon page | All my links
User avatar
airsoftsoftwair
Posts: 5834
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

[09 Feb 2008] Re: Problem inspecting variables

Post by airsoftsoftwair »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Sat, 09 Feb 2008 12:10:44 +0100
Hello, I've a problem inspecting table's elements, I'm not able to check if they exists or not.

For example I have this table: mytable = { }

I can check if the table exists comparing the table against <nil>, for this purpose I have a simple function that do the work: Function IsNil(value) If GetType(value) = #NIL Then Return(1) Else Return(0) EndFunction

But if I want to check an element inside the table the procedure fails, so if I have: mytable = { name = "Fabio" }

NPrint(IsNil(mytable.name)) ; will print 0 NPrint(IsNil(mytable.surname)) ; will raise the error <table field "surname" not initialized!

I'm not able to solve this problem because I need to parse a table with various elements, if they exist I set them, if they not exist I have to get some standard values... in LUA every unset variables are <nil> so this check is very easy. Anyone knows how can I do this job?
This is possible by using the RawGet() function. This function is currently not documented in the Hollywood guide. But it's easy to use. Just pass the table and the index. To check if "surname" is initialized in "mytable" call:

result = RawGet(mytable, "surname") If result = Nil Then NPrint("mytable.surname not initialized")
User avatar
Clyde
Posts: 351
Joined: Sun Feb 14, 2010 12:38 pm
Location: Dresden / Germany

[11 Feb 2008] Re: Problem inspecting variables

Post by Clyde »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Mon, 11 Feb 2008 12:07:47 +0100

Hi!
This is possible by using the RawGet() function. This function is currently not documented in the Hollywood guide.
Interesting. :-) I just wonder how many of these non documented functions are implemented? Do you plan to update the guide in this direction (soon)?

Greetings, Micha

Live long and prosper!
Currently using: Hollywood 9 with Windows IDE and Hollywood 9 with Visual Studio Code and hw4vsc
User avatar
airsoftsoftwair
Posts: 5834
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

[20 Feb 2008] Re: Problem inspecting variables

Post by airsoftsoftwair »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Wed, 20 Feb 2008 01:04:26 +0100
Interesting. :-) I just wonder how many of these non documented functions are implemented? Do you plan to update the guide in this direction (soon)?
Well, "undocumented function" means that it is still subject to change. It's not a product of my laziness :-)
Locked