StrToTable()
StrToTable()
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
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
Re: StrToTable()
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.
You could store your settings as a json file, load and decode it and then you have a table.
Currently using: Hollywood 9 with Windows IDE and Hollywood 9 with Visual Studio Code and hw4vsc
Re: StrToTable()
I don't know if this will help or not, but SplitStr() creates a table from a string.
- airsoftsoftwair
- Posts: 5441
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: StrToTable()
You could also use ReadTable() and WriteTable(). Combining those with a virtual file might give you what you want...
Re: StrToTable()
Thanks guys. Kinda a "duh" moment for me. I figured out how to do it without this function.
Nathan
Nathan
Re: StrToTable()
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 9 with Windows IDE and Hollywood 9 with Visual Studio Code and hw4vsc
- airsoftsoftwair
- Posts: 5441
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: StrToTable()
Actually, this thread motivated me to finally come up with some serialization support in Hollywood. So here it is:
And the first plugin to support serialization is xmlparser.hwp. It can now do the following:
So doing this:
Results in that:
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.
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
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
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$)
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 & How are you"'<>&</cool>
</root>
Re: StrToTable()
Yeah, this is really nice! Thanks, Andreas!
EDIT: But booleans in the table will be converted to 0/1 in the xml, right?
EDIT: But booleans in the table will be converted to 0/1 in the xml, right?
Currently using: Hollywood 9 with Windows IDE and Hollywood 9 with Visual Studio Code and hw4vsc
- airsoftsoftwair
- Posts: 5441
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
- airsoftsoftwair
- Posts: 5441
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: StrToTable()
Code: Select all
- New: Added JSON support; SerializeTable() and DeserializeTable() will now (de)serialize its data to/
from the JSON format by default; you can change this behaviour by specifying the optional adapter
argument; ReadTable(), WriteTable(), LoadPrefs(), and SavePrefs() will continue to use Hollywood's
proprietary table serialization data format for compatibility reasons; you can force those functions
to use JSON, however, by passing "default" in the "Adapter" table field; Hollywood's proprietary table
serializer can be accessed by passing "inbuilt" in the "Adapter" table field