teal-types icon indicating copy to clipboard operation
teal-types copied to clipboard

[on hold] Add Minetest

Open dnchu opened this issue 5 years ago • 3 comments

Question(s):

  • Any plans for "class" inheritance?
  • What is the proper way to use unions and nil?
  • Is it possible to mark a parameter as "non-nil"?

Here is some code that shows some of the weird behavior I get:

function dofile(filename: string)
	...
end
local s: string | nil = somevalue

dofile(s) -- error

if not s is nil then
	dofile(s) -- ok
end

if s is nil then
	dofile(s) -- ok
end

if s then
	dofile(s) -- error
end
if not s then
	return
end

dofile(s) -- error
if s is nil then
	return
end

dofile(s) -- error
Answered questions
  • Is it possible to have an array of multiple types? (Yes, with tl 0.6.0) For example:

    local Image = record 
    	name: string
    end
    local images: {string | Image} = { "diamond_1.png", { name = "diamond_2.png" } }
    
  • Is it possible to allow constructors for records? (Not yet) For example:

    global ItemStack = record
    end
    
    function ItemStack()
    end
    

dnchu avatar Jun 02 '20 17:06 dnchu

Is it possible to have an array of multiple types? For example:

In tl 0.6.0, just released, it is. :) (there was a bug which I fixed)

Is it possible to allow constructors for records? For example:

Not yet... the types have no knowledge of metatables at this point.

hishamhm avatar Jun 03 '20 04:06 hishamhm

Any plans for "class" inheritance?

This is under consideration — discussion ongoing here: https://github.com/teal-language/tl/issues/97 (see also this draft for a simpler variant: https://github.com/teal-language/tl/pull/124 )

What is the proper way to use unions and nil? Is it possible to mark a parameter as "non-nil"?

Not yet. Nil in Teal currently works the same way as in Lua: every variable may be nil, regardless of its type (unions or not). I talk a bit about the challenges involved there in my FOSDEM 2020 talk here: https://www.youtube.com/watch?v=HfnjUCRzRKU

hishamhm avatar Jun 03 '20 19:06 hishamhm

Hey I got something for you https://github.com/jordan4ibanez/forgotten-lands/blob/main/minetest.d.tl Near line 2000 I start my own thing, I've tried my best with this, if there are any updates to it as I'm testing it out I'll keep you updated. Running through the API.md was quite scary haha.

jordan4ibanez avatar Nov 08 '23 00:11 jordan4ibanez