json.hollywood

Show off your project created with Hollywood
Post Reply
User avatar
Clyde
Posts: 198
Joined: Sun Feb 14, 2010 12:38 pm
Location: Dresden / Germany

json.hollywood

Post by Clyde » Tue Aug 27, 2019 3:32 pm

Hi there!

I released the json.hollywood, the json encoder and decoder for Hollywood today: https://github.com/JohnArcher/json.hollywood

It is based on the decode port of "json.lua" (https://github.com/rxi/json.lua) from this forum's user BeChris (thanks, mate!).

I use this library in one of my projects. I wanted to store information in json files so I took to extra step to further port the lua lib to Hollywood.

It is not extensively tested. It just works for my needs. So I would be happy if you use/test it and report issues via the github page or here.

Cheers!
Currently using: Hollywood 8 with Windows IDE

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

Re: json.hollywood

Post by airsoftsoftwair » Sat Aug 31, 2019 1:46 pm

Good to see that there's a JSON parser for Hollywood now!

Btw, you might want to change http://www.hollywood-mal.de/ to http://www.hollywood-mal.com/ in README.md because it's in English...

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

Re: json.hollywood

Post by Clyde » Sat Aug 31, 2019 11:13 pm

You are right, nice catch, thank you. Changed.
Currently using: Hollywood 8 with Windows IDE

Bugala
Posts: 825
Joined: Sun Feb 14, 2010 7:11 pm

Re: json.hollywood

Post by Bugala » Wed Sep 25, 2019 10:30 am

It looks like this JSON could be solution to my problem. I am actually still not sure what this JSON exactly is, hence I am asking about this.

What I am trying to do is to have something like this for example:

Code: Select all

Capitol:
EnemyGenerator("thieves", 10)
EnemyGenerator("orcs", 1)
AddEvent("earthquake", 2, 3)
So basically I am after won scripting language that i can write as a txt file.

In this case when i enter city called "Capitol" it would use these EnemyGenerator commands to create Thieves and Orcs and also adding event possibility for Eathquake with "AddEvent"-command.

Idea being that when I read that file, I can read these into some sort of table, which could result in for example following:

Code: Select all

script = {
	[1] = { command = "EnemyGenerator", chance = 10},
	[2] = { command = "EnemyGenerator", chance = 1},
	[3] = { command = "AddEvent, chance = 2, power = 3}
           }
Looks a lot like JSON could be the answer, but is JSON only for the values, and not for commands at all?
For when I try using JSON, as first command in my file is DisplayPicture(100, 100, "test.jpg) it already says line 1 col 1 (D) is an error.

So can JSON actually take those commands, or is it just for values or what is it?

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

Re: json.hollywood

Post by Clyde » Wed Sep 25, 2019 12:44 pm

Could you please provide a small real example with the structure/table you want to convert to JSON?

What the json encoder does is taking a Hollywood table and converts it to json (and the decoder takes the json and converts it back to a table).

So, seeing your first code snipped (starting with "Capitol"), this cannot be converted to json directly, but your second snippet("script = { ...") should work.
Currently using: Hollywood 8 with Windows IDE

Bugala
Posts: 825
Joined: Sun Feb 14, 2010 7:11 pm

Re: json.hollywood

Post by Bugala » Wed Sep 25, 2019 1:26 pm

Okay, then JSON in its current state is not answer to my problem. By the way, i made mistake on that table example:

Code: Select all

script = {
	[1] = { command = "EnemyGenerator", enemytype="thieves", chance = 10},
	[2] = { command = "EnemyGenerator", enemytype="orcs", chance = 1},
	[3] = { command = "AddEvent, eventtype="earthquake", chance = 2, power = 3}
           }
But I wonder if I could get JSON to ignore the command parts from the txt file lines, and could just use them to get the values, since I could use my own system to get the commands read.

For right now problem is that if i have those commands there, it stops execution and errors.

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

Re: json.hollywood

Post by Clyde » Wed Sep 25, 2019 1:45 pm

Well, this is not the task of JSON or the JSON encoder/decoder. JSON is just another representation of structuring data. You have to write your own converting code to convert from your txt file format to a Hollywood table.
Currently using: Hollywood 8 with Windows IDE

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

Re: json.hollywood

Post by airsoftsoftwair » Wed Oct 30, 2019 4:43 pm

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

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

Re: json.hollywood

Post by Clyde » Mon Nov 04, 2019 9:05 am

Very nice, thanks!
Currently using: Hollywood 8 with Windows IDE

Post Reply