-- Shapes.pln
local Shapes: module = {}
record Circle
radius: float
end
record Rectangle
length: float
width: float
end
function Shapes.Circle_New(r: float): Circle
local c: Circle = {radius = r}
return c
end
function Shapes.Circle_Area(c: Circle): float
return c.radius * c.radius * 3.1415
end
function Shapes.Rectangle_New(l: float, w: float): Rectangle
local c: Rectangle = {length = l, width = w}
return c
end
function Shapes.Rectangle_Area(c: Rectangle): float
return c.length * c.width
end
return Shapes
Old behaviour
❯ lua main.lua
lua: main.lua:8: file Shapes.pln: line 17: wrong type for argument 'c', expected userdata but found userdata
stack traceback:
[C]: in function 'Shapes.Circle_Area'
main.lua:8: in main chunk
[C]: in ?
❯ lua main.lua
lua: main.lua:9: file Shapes.pln: line 17: wrong type for argument 'c', expected userdata but found integer
stack traceback:
[C]: in function 'Shapes.Circle_Area'
main.lua:9: in main chunk
[C]: in ?
New behaviour
❯ lua main.lua
lua: main.lua:8: file Shapes.pln: line 17: wrong type for argument 'c', expected Circle but found Rectangle
stack traceback:
[C]: in function 'Shapes.Circle_Area'
main.lua:8: in main chunk
[C]: in ?
❯ lua main.lua
lua: main.lua:9: file Shapes.pln: line 17: wrong type for argument 'c', expected Circle but found integer
stack traceback:
[C]: in function 'Shapes.Circle_Area'
main.lua:9: in main chunk
[C]: in ?
Fixes: #151
Code:
Old behaviour
New behaviour