rhaiscript / book

The Rhai Book.
https://rhai.rs/book
22 stars 22 forks source link

Oop export #22

Closed ltabis closed 1 year ago

ltabis commented 1 year ago

This is not mentioned in the OOP chapter, but objects cannot be exported by modules if they contain anonymous functions. I added a warning with a few explanation and a possible way to get over it.

Edit: Because of my fork this PR also contains a CI script to check for broken links automatically, tell me if this needs to be removed.

schungx commented 1 year ago

Actually objects containing anonymous functions can be exported from modules. I fixed that a while ago.

Not sure if it is in the current release. I'll check...

EDIT: This should be live in 1.14.0. Can you check?

This is from the changes log:

ltabis commented 1 year ago

EDIT: This should be live in 1.14.0. Can you check?

Yes, it does work, my bad. I was testing it with arrays embedded in the object, for example:

export const object = #{
    x: [
        || print("test1"),
        || print("test2"),
    ]
};

export const object = [
        || print("test1"),
        || print("test2"),
    ];

I was not working with objects, my mistake !

ltabis commented 1 year ago

BTW @schungx you can actually export anonymous functions using a custom implemented macro that copy the entire module script into the main script. I think it's a bad solution but it works.

schungx commented 1 year ago

Ah... So arrays didn't work? They should...

schungx commented 1 year ago

BTW @schungx you can actually export anonymous functions using a custom implemented macro that copy the entire module script into the main script. I think it's a bad solution but it works.

That would probably be too much if the script is too large...

ltabis commented 1 year ago

Ah... So arrays didn't work? They should...

I believe they work. Looking back at my discord message it's just that I was trying to execute those on the Rust side !