Inspecting nested tables

Find quick help here to get you started with Hollywood
Post Reply
GMKai
Posts: 140
Joined: Mon Feb 15, 2010 10:58 am

Inspecting nested tables

Post by GMKai »

Hello, I try to implement Enums with Hollywood,
this is an excerpt:

Code: Select all

EnumBox = {storage = {}}
EnumEntry = {key ="",msgid="",value=""}

Function EnumEntry:Create(key,msgid,value)
    t = CopyTable(self)
    t.key = key
    t.msgid = msgid
    t.value = value
    EnumBox:Add(t)
EndFunction       
 
Function EnumBox:Add(entry)
    ;check if already exists
    Local ret = EnumBox:CheckExist(entry)
    If(ret = 0)
       InsertItem(self.storage, entry)
    EndIf()
EndFunction

Function EnumBox:CheckExist(entry)
    Local a, b = NextItem(EnumBox.storage)
    While GetType(a) <> #NIL
      ;DebugPrint(b.key.."--"..b.msgid.."--"..b.value)
      If(entry.key = b.key and entry.msgid = b.msgid and entry.value = b.value)
         Return(1)
      EndIf()
      a, b = NextItem(EnumBox.storage, a)
    Wend
    Return(0)
EndFunction       
Is there a nicer way to check if a tableentry is already saved within a table?
Can the statement

Code: Select all

t = CopyTable(self)
be avoided?
p-OS
Posts: 167
Joined: Mon Nov 01, 2010 11:56 pm

Re: Inspecting nested tables

Post by p-OS »

Maybe you could post an example of how your table of enums shall lool like in the end ?
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Inspecting nested tables

Post by airsoftsoftwair »

I don't know what exactly the OP is trying to do here either... more details, please...
p-OS
Posts: 167
Joined: Mon Nov 01, 2010 11:56 pm

Re: Inspecting nested tables

Post by p-OS »

He tries to simulate ENUMs from Java. But his code might be little bit ineffective ;)
GMKai
Posts: 140
Joined: Mon Feb 15, 2010 10:58 am

Re: Inspecting nested tables

Post by GMKai »

Yes indeed,
idea is to get something like a java-enum.
The storage is:
EnumBox = {storage = {}}
EnumEntry = {key ="",msgid="",value=""}

where "EnumBox" holds all Enums that can be defined during runtime.
A single EnumEntry can be compared to a constant,

What I hope to achieve is a way to handle complex situations with (extended) key-value pairs.
In the code one can handle numerical comparisons, and with some extrainformation one can do something more, like inform a user or do followup-calculation,

When an entry represents an event/situation one can lookup msgid and value and decide what to do.
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Inspecting nested tables

Post by airsoftsoftwair »

Well, I don't know anything about Java enums but it should be possible to emulate those in Hollywood. Maybe this link helps: http://unendli.ch/posts/2016-07-22-enum ... n-lua.html
Post Reply