jingoro2112 / wrench

practical embedded script interpreter
MIT License
99 stars 10 forks source link

Feature request: nested hash maps declaration (collections) #22

Closed ohordiichuk closed 1 month ago

ohordiichuk commented 1 month ago

Hello,

while it seems the VM is already supporting nesting the collections by storing them in different variables (as far as I understand from C++ code it works because variables could be stored as references):

// it works
var a = {"test1": 1, "test2": 4};
var b = {"test2" : 2};
var c = {"test4": 54};

b.test3 = a;
b.test3.test4 = c;
print(b.test3.test4.test4);

it's not possible to declare nested hash maps with 1 variable:

// it doesn't work (feature request)
var a = {"test1": {"test2" : 1}};

And also it's not possible to assign another collection to a key of existing collection:

// it doesn't work (feature request)
var a = {"test1" : 1};
a.test2 = {"test3" : 2};
jingoro2112 commented 1 month ago

hmm... yeah I can do this the first is easy but the second will be more of a challenge.

MaxTymchii commented 1 month ago

Hi there @jingoro2112 ,

I want to achieve the next functionality, but it seems there is no such a strait forward solution for that:

var table = {};
table["a"] = 100;
table["b"] = 1200;
table["c"] = 10;

Can you give me some advice on how to do that?

jingoro2112 commented 1 month ago

I am actually working on the hash/array parsing right now. This does work but you need to declare table as a hash, not an array:

var table = {:}; // note ':' making this a hash table

table["a"] = 100; table["b"] = 1200; table["c"] = 10;

println( table["a"], " ",table["b"], " ",table["c"], " " );

produces the output:

./wrench r test.c100 1200 10

Without the colon you declared 'table' as an array. I definitely need to make this more clear in the future, any suggestions are welcome!

On Fri, Jun 7, 2024 at 12:49 PM Max @.***> wrote:

Hi there @jingoro2112 https://github.com/jingoro2112 ,

I want to achieve the next functionality, but it seems there is no such a strait forward solution for that:

var table = {}; table["a"] = 100; table["b"] = 1200; table["c"] = 10;

Can you give me some advice on how to do that?

— Reply to this email directly, view it on GitHub https://github.com/jingoro2112/wrench/issues/22#issuecomment-2155192542, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALIKA3RPTVR5TGZO62ITDDZGHQDJAVCNFSM6AAAAABISWUYNCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNJVGE4TENJUGI . You are receiving this because you were mentioned.Message ID: @.***>

MaxTymchii commented 1 month ago

Thx! Now it's more clear. Adding such examples to your website will help to avoid such issues in the future.

Another thing that I am working on now is testing scripts. The import feature is really helpful on it, but it's a lot of work that could be done in that field for me.

MaxTymchii commented 1 month ago

One more off-topic thing. What IDE do you use for your development?

jingoro2112 commented 1 month ago

I totally agree that documentation and examples could be better. I'm sort of hoping as wrench gets more use I'll visit more and more parts of it for polish. Keep in mind as much as I take pride in fixing bugs quickly and having clean code, it's just me and this is not my dayjob :)

For code-editing I use epsilon (https://www.lugaru.com/), but for general development and debugging I use Visual Studio, currently 2022.

-Curt

On Fri, Jun 7, 2024 at 1:51 PM Max @.***> wrote:

One more off-topic thing. What IDE do you use for your development?

— Reply to this email directly, view it on GitHub https://github.com/jingoro2112/wrench/issues/22#issuecomment-2155271620, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALIKA5IA6KQVPZYA5EEOZ3ZGHXJNAVCNFSM6AAAAABISWUYNCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNJVGI3TCNRSGA . You are receiving this because you were mentioned.Message ID: @.***>

jingoro2112 commented 1 month ago

This has been completed in version 5.0.1

jingoro2112 commented 1 month ago

Just replying in thread for anyone interested.. the current release 5.0.1 has all feature-requests (nested declaration etc) completed.

-Curt

On Fri, Jun 7, 2024 at 2:44 PM Curt Hartung @.***> wrote:

I totally agree that documentation and examples could be better. I'm sort of hoping as wrench gets more use I'll visit more and more parts of it for polish. Keep in mind as much as I take pride in fixing bugs quickly and having clean code, it's just me and this is not my dayjob :)

For code-editing I use epsilon (https://www.lugaru.com/), but for general development and debugging I use Visual Studio, currently 2022.

-Curt

On Fri, Jun 7, 2024 at 1:51 PM Max @.***> wrote:

One more off-topic thing. What IDE do you use for your development?

— Reply to this email directly, view it on GitHub https://github.com/jingoro2112/wrench/issues/22#issuecomment-2155271620, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALIKA5IA6KQVPZYA5EEOZ3ZGHXJNAVCNFSM6AAAAABISWUYNCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNJVGI3TCNRSGA . You are receiving this because you were mentioned.Message ID: @.***>

ohordiichuk commented 1 month ago

Curt, thank you for all your efforts! We will try everything out soon together with Max.

We have also successfully compiled wrench in Emscripten and will try to embed this library into our backend code. Later we can share details if that will be interesting for anybody.

We also tried to create a syntax highlighting plugin for VSCode. It's very basic currently and not everything is working. But if we will manage to have something working good, we will share it.

jingoro2112 commented 1 month ago

Yes please any info/contributions are most welcome. Also please don't hesitate to tell me about any bugs/anomalies/feature requests you have. I am anxious to improve.

On Sun, Jun 9, 2024 at 12:10 PM ohordiichuk @.***> wrote:

Curt, thank you for all your efforts! We will try everything out soon together with Max.

We have also successfully compiled wrench in Emscripten and will try to embed this library into our backend code. Later we can share details if that will be interesting for anybody.

We also tried to create a syntax highlighting plugin for VSCode. It's very basic currently and not everything is working. But if we will manage to have something working good, we will share it.

— Reply to this email directly, view it on GitHub https://github.com/jingoro2112/wrench/issues/22#issuecomment-2156680181, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALIKA66D6PBHFVWJ2IOIVLZGR453AVCNFSM6AAAAABISWUYNCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNJWGY4DAMJYGE . You are receiving this because you were mentioned.Message ID: @.***>