lua-users home
lua-l archive

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

On 6/11/07, Steve Heller <> wrote:
I'm trying to do machine translation from an extremely
"loose" language to Lua. What I mean by "loose" is
that this language doesn't even have run-time typing.
You can compare strings and numbers and it converts

I need to find all the occurrences of these type
mismatches so my Lua translation will work correctly.
Order comparisons like '<' and '>=' will throw a
runtime error, so I can catch them and fix the code.
However, '==' and '~=' always produce false and true
respectively for values that don't have the same type,
so I won't know that there is a type mismatch.

Does anyone have any suggestions as to how to catch
these errors?

My first idea would be to try creating a metatable with an entry for
eq and attaching it to a number value. According to the manual all
number values share a single common metatable. The same applies to
strings. I don't know it this really works, but if it does it would be
everything that is needed. Note that the manual says the metatable for
non-table values can only be changed in C code.

Hope this helps

(defun f(p x)(If(Eq x nil)nil(If(p(Car x))(Cons(Car x)(f p(Cdr x)))(f p
(Cdr x)))))(defun q(x)(Q nil x))(defun Q(a x)(If(Eq x nil)a(Q(Cons(Car
x)(Q a(f(Lt(Car x))(Cdr x))))(f(Gt(Car x))(Cdr x)))))