|
I suggested this back in Lua Oh Six (2006). Don't know why nothing much has happened on the area. Both luaSub and the other filtering solution do implement it (so look at them instead of rolling your own), but the consensus on the list seemed to be that such "half static" checking would not be required, or that it would be outright negative for the Lua as a language. I never understood this reasoning.
About extending with one's own types (i.e. objects that are supposed to have certain fields), luaSub defines the tests by making 'type' and 'assert' be tables (backwards compatible with Lua 5.1 API). So you can do:
type.foo= function ... assert.foo= function ...Built-in functions s.a. type.table, type.int, type.number and so on of course exist.
Token filtering is the right approach to do this. I did try a patch earlier, but the area is way too complex for a proper patch. That means the patch gets fairly big.
I would really like this feature in future Lua. Built-in and allowing the use of even some static type checking tools (s.a. lua-lint) to find those mistakes that can be at compilation time.
-asko matias.guijarro@free.fr kirjoitti 7.7.2009 kello 16:31:
Hello, I would like to Luiz's token filter facility in order to add runtime function argument type checking in some Lua code, e.g something along the lines of : function F(x :: integer, y :: float) ... do something useful ... end This type checking would be optional. Of course, it would not be limited to integer or float, ideally I would like to be able to define my own types. Is it a good idea to use token filtering ? Does someone already did something similar ? (don't want to reinvent a wheel !) Anyway before starting anything interesting, I have a first problem : the token filter patch doesn't work as I expect ; I just compiled a brand new Lua 5.1.4 with the patch and tried fdebug.lua ; here is what I get : Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Riodofile("fdebug.lua") print(1+2)FILTER =stdin FILTER 1 <name> print FILTER 1 ( nil FILTER 1 <number> 1 FILTER 1 + nil FILTER 1 <number> 2 FILTER 1 ) nil FILTER 1 <eof> nil 3print(1+2)FILTER 0 <eof> nil FILTER 0 <eof> nilWhy the second "print" is not displaying the same output ??? I find this very confusing. Thanks in advance for any help, cheers, Matias.