You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey all! I'm working on a small side project and one of the things I'd like to do involves porting some Lua code over to Luau. The current code exposes a lot of native modules that can be used via require() statements. E.g.
localsomeLibrary=require('some-c-library')
Luau doesn't like this since it can't find the module. From what I've seen looking at docs and rfcs, I don't think there's currently a way to do this that Luau likes. It looks like the current declaration syntax only works for declaring globals.
Proposal
Adding modules to the current declaration syntax. Something like,
-- types.d.luau-- Module exporting a tabledeclaremodule'some-c-library' {
sum: (a: number, b: number) ->number-- ...other module exports here
}
-- Module exporting a stringdeclaremodule'some-other-library' string-- some-source-file.luaulocalsomeLibrary=require('some-c-library')
print(someLibrary.sum(1, 2))
print(require('some-other-library'))
This would,
Declare the module so that require() resolves it and the type it returns
Throw at runtime if the vm can't resolve the require()
The text was updated successfully, but these errors were encountered:
Luau doesn't like this since it can't find the module. From what I've seen looking at docs and rfcs, I don't think there's currently a way to do this that Luau likes. It looks like the current declaration syntax only works for declaring globals.
The way to do this in a way that luau "likes" is to create a module resolver compatible with the Analysis library. This allows the analyzer to discover built-in module types at compile time. You can check the CLI implementation at struct CliFileResolver : Luau::FileResolver in Analyze.cpp.
Note that this means you will probably need to ship your own analysis binaries that use your fancy custom file resolver.
Background
Hey all! I'm working on a small side project and one of the things I'd like to do involves porting some Lua code over to Luau. The current code exposes a lot of native modules that can be used via
require()
statements. E.g.Luau doesn't like this since it can't find the module. From what I've seen looking at docs and rfcs, I don't think there's currently a way to do this that Luau likes. It looks like the current declaration syntax only works for declaring globals.
Proposal
Adding modules to the current declaration syntax. Something like,
This would,
require()
resolves it and the type it returnsrequire()
The text was updated successfully, but these errors were encountered: