StrToTable()

Feature requests for future versions of Hollywood can be voiced here
Post Reply
NathanH
Posts: 19
Joined: Sun Jul 05, 2015 1:29 am

StrToTable()

Post by NathanH » Mon Sep 16, 2019 1:55 am

I'm trying to create user-defined menus so am creating the menu at run-time, not compile-time. I parse the menu definition and DOS/REXX commands from a user file. I have compiled the menu definition in the correct format in a string. CreateMenu() complains that it wants a table, however. The above function would allow programmatically created tables from strings.

As an aside, I like to keep separate the operating system from other commands, scripts, tools, and utilities that I might download or write. I then add Extras:C, Extras:Libs, etc. to the existing assigns. It appears that Hollywood is hard-coded to look in SYS:Libs for its libraries rather than in LIBS:. It would be more Amiga-like to look in LIBS:.

Thanks for asking for wishes.

NathanH

User avatar
Clyde
Posts: 195
Joined: Sun Feb 14, 2010 12:38 pm
Location: Dresden / Germany

Re: StrToTable()

Post by Clyde » Mon Sep 16, 2019 2:44 pm

Regarding your first wish you could try my json decoder/encoder: https://github.com/JohnArcher/json.hollywood

You could store your settings as a json file, load and decode it and then you have a table.
Currently using: Hollywood 8 with Windows IDE

PEB
Posts: 253
Joined: Sun Feb 21, 2010 1:28 am

Re: StrToTable()

Post by PEB » Mon Sep 16, 2019 5:36 pm

I don't know if this will help or not, but SplitStr() creates a table from a string.

User avatar
airsoftsoftwair
Posts: 3159
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: StrToTable()

Post by airsoftsoftwair » Wed Sep 18, 2019 10:20 pm

You could also use ReadTable() and WriteTable(). Combining those with a virtual file might give you what you want...

NathanH
Posts: 19
Joined: Sun Jul 05, 2015 1:29 am

Re: StrToTable()

Post by NathanH » Thu Sep 19, 2019 3:36 am

Thanks guys. Kinda a "duh" moment for me. I figured out how to do it without this function.

Nathan

User avatar
Clyde
Posts: 195
Joined: Sun Feb 14, 2010 12:38 pm
Location: Dresden / Germany

Re: StrToTable()

Post by Clyde » Thu Sep 19, 2019 9:20 am

Nice that you sorted it out. But maybe you could provide or describe your solution Could help others and would be interesting. Thanks!
Currently using: Hollywood 8 with Windows IDE

User avatar
airsoftsoftwair
Posts: 3159
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: StrToTable()

Post by airsoftsoftwair » Tue Oct 01, 2019 4:27 pm

Actually, this thread motivated me to finally come up with some serialization support in Hollywood. So here it is:

Code: Select all

- New: Added SerializeTable() and DeserializeTable() for conveniently converting a table into a string
  and back using a serializer plugin
- New: LoadPrefs() and SavePrefs() accept a new optional table argument now which accepts an "Adapter" 
  tag which allows you to specify a plugin to be used for serializing the data
- New [SDK]: Added HWPLUG_CAPS_SERIALIZE which allows plugins to hook into Hollywood's new serializing
  capabilities offered by WriteTable() and ReadTable()
- New: WriteTable() and ReadTable() accept a new "Adapter" tag now which can be used to route those
  calls through external plugins supporting Hollywood's new serialization interface 
And the first plugin to support serialization is xmlparser.hwp. It can now do the following:

Code: Select all

- New: Plugin supports Hollywood 8.1's new serialization capabilities now; this means that
  you can easily serialize a table to XML using Hollywood's WriteTable()/SerializeTable()/
  SavePrefs() functions and read it back into a table using ReadTable()/DeserializeTable()/
  LoadPrefs(); even the serialization of binary data and functions is fully supported
So doing this:

Code: Select all

t = {test = 1, bla = "Hello World", table1 = {table2 = {table3 = {af = "test"}}}, cool = "Hello & How are you\"'<>&", 1, 2, 3, 4, 5,
	subnode = {1,2,3,4,5, yooguys = 0.4567}, yeah = "12345", functest = Function(a, b, c)
		DebugPrint("Hello World this is a test", a, b, c) EndFunction}
a$ = SerializeTable(t, "xmlparser")
DebugPrint(a$)
Results in that:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<root>
        <item.1>2</item.1>
        <item.2>3</item.2>
        <item.3>4</item.3>
        <item.4>5</item.4>
        <functest type="function">
                G0hXQgEECAQGCAkJCLYJk2jn9X1BAgAAAAAAAAA/AEwAAAAAAwAIBwAAAE0AAABNAAAATQAAAE0AAABN
                AAAATQAAAE0AAAADAAAAAgAAAAAAAABhAAAAAAAGAAAAAgAAAAAAAABiAAAAAAAGAAAAAgAAAAAAAABj
                AAAAAAAGAAAAAAAAAAIAAAAECwAAAAAAAABkZWJ1Z3ByaW50AAQbAAAAAAAAAEhlbGxvIFdvcmxkIHRo
                aXMgaXMgYSB0ZXN0AAAAAAAHAAAABQAAA0EAAAQAAAAFAIAABgAAAQdggAIDIoAAAA==
        </functest>
        <item.0>1</item.0>
        <bla>Hello World</bla>
        <subnode>
                <item.1>2</item.1>
                <item.2>3</item.2>
                <item.3>4</item.3>
                <item.4>5</item.4>
                <item.0>1</item.0>
                <yooguys>0.4567</yooguys>
        </subnode>
        <yeah type="string">12345</yeah>
        <test>1</test>
        <table1>
                <table2>
                        <table3>
                                <af>test</af>
                        </table3>
                </table2>
        </table1>
        <cool>Hello &amp; How are you&quot;&apos;&lt;&gt;&amp;</cool>
</root>
And DeserializeTable() can be used to convert the XML above back into a table. I think this is very useful and it's quite powerful as well.

User avatar
Clyde
Posts: 195
Joined: Sun Feb 14, 2010 12:38 pm
Location: Dresden / Germany

Re: StrToTable()

Post by Clyde » Tue Oct 01, 2019 5:03 pm

Yeah, this is really nice! Thanks, Andreas!

EDIT: But booleans in the table will be converted to 0/1 in the xml, right?
Currently using: Hollywood 8 with Windows IDE

User avatar
airsoftsoftwair
Posts: 3159
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: StrToTable()

Post by airsoftsoftwair » Tue Oct 01, 2019 6:22 pm

Clyde wrote:
Tue Oct 01, 2019 5:03 pm
EDIT: But booleans in the table will be converted to 0/1 in the xml, right?
Hollywood doesn't support booleans. Booleans are just numbers which means that they will indeed appear as 0 and 1 in the XML.

Post Reply