Inspecting nested tables

Find quick help here to get you started with Hollywood

Inspecting nested tables

Postby GMKai » Wed Apr 05, 2017 8:53 pm

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?
GMKai
 
Posts: 52
Joined: Mon Feb 15, 2010 11:58 am

Re: Inspecting nested tables

Postby p-OS » Fri Apr 07, 2017 4:17 pm

Maybe you could post an example of how your table of enums shall lool like in the end ?
p-OS
 
Posts: 72
Joined: Tue Nov 02, 2010 12:56 am

Re: Inspecting nested tables

Postby airsoftsoftwair » Sun Apr 09, 2017 3:03 pm

I don't know what exactly the OP is trying to do here either... more details, please...
User avatar
airsoftsoftwair
 
Posts: 2202
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany

Re: Inspecting nested tables

Postby p-OS » Sun Apr 09, 2017 10:17 pm

He tries to simulate ENUMs from Java. But his code might be little bit ineffective ;)
p-OS
 
Posts: 72
Joined: Tue Nov 02, 2010 12:56 am

Re: Inspecting nested tables

Postby GMKai » Mon Apr 10, 2017 11:18 am

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.
GMKai
 
Posts: 52
Joined: Mon Feb 15, 2010 11:58 am

Re: Inspecting nested tables

Postby airsoftsoftwair » Tue Apr 11, 2017 11:50 am

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
User avatar
airsoftsoftwair
 
Posts: 2202
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany


Return to Newbie questions

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron