andremm / typedlua

An Optional Type System for Lua
565 stars 53 forks source link

insert dynamic type checking code #109

Open tmbdev opened 7 years ago

tmbdev commented 7 years ago

I'd like to use typedlua to compile code for use in regular, dynamically typed Lua applications. That is, most of the code that will be using my code as a library is likely going to be not statically typed.

For that, I'd find it useful if there was an option to have typedlua insert type checking code at the boundary between dynamic Lua code and typedlua code.

Concretely, I'd find it useful if "typedlua -t example.lua" would transform something like this:

function f(x: string): string
    return x..x
end

into

f = function (x) 
  if type(x) ~= "string" then error("function f, argument x:string, got "..type(x)) end
  return x .. x
end