lenscas / tealr

A wrapper around mlua and rlua to generate documentation and other helpers
66 stars 7 forks source link

Does tealr support mlua's luau? #77

Closed Gabryx64 closed 1 year ago

lenscas commented 1 year ago

Luau doesn't have a way to create type definition files so there is no way to tell luau about the types and functions you expose to it at compile time like tealr can do for teal.

Other that that, nothing should prevent tealr from working with luau. I just need to add a feature in tealr that enables it and changes its api to match the changes in mlua, if I didn't already do that.

Gabryx64 commented 1 year ago

Other that that, nothing should prevent tealr from working with luau. I just need to add a feature in tealr that enables it and changes its api to match the changes in mlua, if I didn't already do that.

Apparently there is no mlua_luau feature yet

khvzak commented 1 year ago

Luau doesn't have a way to create type definition files so there is no way to tell luau about the types and functions you expose to it at compile time

Actually you can tell luau analyzer about type definitions you expose, for example:

export type MyType = {
    field: string,
    method: (string) -> (),
    ...
}

you can load exports from a lua file and refer to them later.

It's not really documented, only mentioned in https://luau-lang.org/typecheck#module-interactions

lenscas commented 1 year ago

Luau doesn't have a way to create type definition files so there is no way to tell luau about the types and functions you expose to it at compile time

Actually you can tell luau analyzer about type definitions you expose, for example:

export type MyType = {
    field: string,
    method: (string) -> (),
    ...
}

you can load exports from a lua file and refer to them later.

It's not really documented, only mentioned in https://luau-lang.org/typecheck#module-interactions

I'm not quite sure how or why, but I have a gut feeling that relying on this will produce problems as tealr (and mlua for that matter) mostly expose new types, functions and values as new globals. This works fine with teal as you can load .d.tl files globally using the tlconfig.lua file.

Something like this doesn't seem possible with luau and I'm not sure if putting the require's to.lua files would work properly or if there will be (small) inconsistencies because of this. Someone who knows luau better than me can probably get this working I suppose though.

lenscas commented 1 year ago

Other that that, nothing should prevent tealr from working with luau. I just need to add a feature in tealr that enables it and changes its api to match the changes in mlua, if I didn't already do that.

Apparently there is no mlua_luau feature yet

Not sure when I have time to add one. It shouldn't be too hard though. Just add the feature in the cargo.toml file like I did for the other lua versions, enable it and fix the compile errors by disabling stuff that is not available in mlua when luau is used, exactly the same way as is done for the other lua versions.

After that, it is just a quick look at mlua's docs to make sure that not too much is disabled.