lua-users home
lua-l archive

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

A better solution may be to _not_ use the : syntax at all.

I've recently crafted an API for non-programmers, and decided to make the whole object system using dot notation. Exactly for the reason of not confusing the users on when they need dot, when colon. It's always dot.

This is performed by sending the 'this' object as upvalue to all the methods. It may give a slight runtime penalty but I doubt it's even measurable. Can show you sample if you are interested, but the technique has been mentioned on the list before.


Christopher Eykamp kirjoitti 17.2.2010 kello 2:05:

I'm working on a C++ game that uses Lua scripts to control robot players. I'm noticing a common error that the scripters are making, and am looking for a way to detect it and print a helpful error message.

When the scripters should be writing:


they often write:


which looks similar but is of course very different. However, anyone with much experience in Java, C++, etc., is conditioned to see the second (wrong) version as right, so this is a very difficult bug to detect while reading the code.

In the setAngle function, I check that the correct number of parameters is passed, and I generate an error message if that happens. What I'd like to do is augment that mechanism by checking if the user used the "." variant and display a different message that suggests they verify that they meant to use "." and not ":".

Is there a way from C++ to figure out if a function was called using "." as opposed to ":"?