teal-language / tl

The compiler for Teal, a typed dialect of Lua
MIT License
2.1k stars 108 forks source link

Suggestion: "tl.lua" to be more restrictive #568

Closed cattokomo closed 1 year ago

cattokomo commented 1 year ago

Hello! I have suggestion to make tl.lua to be more restrictive with types declaration and things, like the tl compiler.

The reason I want to have more static typed .tl modules/scripts for Tluvit loader. With this feature being added to tl.lua, this giving others who didn't know Teal is interested of using it within any Lua runtime.

Example

In mdl.tl:

local myModule = {
  myA = 'a',
  myB_func = function(a: string,b: number): string
    return a..b
  end,
  myC = {1,2,'c'}
}

return myModule

In maintl.tl:

local myModule = require 'mdl' -- Error, no "mdl.d.tl"

myModule.myA = true -- Error, convert string variable to boolean
myModule.myB_func('test','2') -- Error, argument #2 takes string not number
myModule.myC = nil -- Error, convert table to nil

And then run the maintl.tl in main.lua with code require 'tluvit'.loadtl() (Luvit runtime)

lenscas commented 1 year ago

Hello! I have suggestion to make tl.lua to be more restrictive with types declaration and things, like the tl compiler.

The tl.lua file IS the teal compiler, just already compiled to lua. So, I'm not sure what you mean with this.

cattokomo commented 1 year ago

The tl.lua file IS the teal compiler, just already compiled to lua. So, I'm not sure what you mean with this.

I mean the tl.lua should throw error if there's wrong type or things, like the above.

lenscas commented 1 year ago

Again, tl.lua is the teal compiler, there is no difference between tl.tl and tl.lua. please explain how you are running it.

If you want the lua VM to be able to load teal scripts and check for errors then I thought that https://github.com/teal-language/tl/commit/16761188d64a14b9a31c09ff18d6ff7b8715d4cf was to get that working? Might be wrong though.

cattokomo commented 1 year ago

That's what I looking for!