Page 1 of 1
[08 Feb 2008] Problem inspecting variables
Posted: Sat Jun 13, 2020 5:31 pm
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:
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
[09 Feb 2008] Re: Problem inspecting variables
Posted: Sat Jun 13, 2020 5:31 pm
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")
[11 Feb 2008] Re: Problem inspecting variables
Posted: Sat Jun 13, 2020 5:31 pm
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!
[20 Feb 2008] Re: Problem inspecting variables
Posted: Sat Jun 13, 2020 5:31 pm
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