lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 23.10.2012 21:58, Geoff Leyland wrote:

I suppose I could write a function "checkargs"

iirc the Sierra Wireless folks did something like that.

Indeed we have...

If you're talking about run-time rather than static type-checking, then [1] shamelessly copies the sierra wireless solution, except that it runs as a debug hook, reads documentation comments rather than requiring a check function and is in Lua as opposed to C (nothing against C, just that a Lua-only solution doesn't require compilation).


     --- prints the string s n times
     -- @tparam number n how many times to print the string
     -- @tparam string s the string to print
     function printn(s, n)
       for i = 1, n do print(s) end
     end

     printn(10, "hello")


     $ lua -largcheck test/ldoc.lua
     lua: test/ldoc.lua:8: bad argument #1 to 'printn' (string expected, got number '10')

what about

printn("hello",'10')

?