-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API: expose a way to programmatically create a typed environment for tl.load/process/etc. #248
Comments
As for type checking Other alternatives I can think of is switching from lua to teal for it, which would allow the use of the compiler to typecheck it but means that the config file needs to be compiled before it can be used, which seems weird. Last option I can think of is to switch to json/some other format that supports schemas. Then any tool can typecheck the config file without having to depend on teal themselves, as a bonus vscode (and other editors) can already add autocomplete suggestions. Personally, I'm not even sure why the config file is in lua except for it saving a dependency. It isn't like the tlconfig.lua is supposed to run code, is it? (Frankly, I don't even want to imagine the kind of horrors that people could/will turn their tlconfig.lua into if they start to use actual code in it....) |
(Sorry for the wall of text, but I've been thinking about solutions to this a lot! 😄)
For the compiler to type check it needs types defined somewhere, currently you can hackishly prepend some typedefs to the start of your source code before calling something like
Or as you suggest we could have something like a .d.tl file for the config file types and have Teal load it before loading the config, but I am of the opinion that it would be better to define these types in statically verifiable code.
(And somehow have the return type verified as well) Personally, I like taking advantage of Lua's syntactic sugar for making config formats and for my cli, the config options are set by some globals that are injected into the config's environment project "deps" {
"luafilesystem"
}
build "options" {
source_dir = "src",
build_dir = "build"
} Since the values are passed through what are basically glorified setters, they can be processed a little more nicely than iterating over a table and picking out the keys you recognize. I think type checking it is a bit easier since we don't have to tell
Saving a dependency and Lua is good at being a configuration/data description language, it was designed with it in mind.
I mean, Makefiles and the like could just put a |
I'm currently working on my own cli to Teal for a few reasons
One of the biggest issues is that I want config files to be type checked by Teal (as well as
tlconfig.lua
here and an eventualbuild.tl
). Right now the util module is pulling a lot of weight by doing some runtime type checking but this feels wrong.So when
tl.tl
eventually gets split up, I think this is an important feature for tooling to have.The text was updated successfully, but these errors were encountered: