[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Namespace pollution in lua.h
- From: David Jones <djones@...>
- Date: Fri, 11 May 2001 09:14:07 +0000
The interface to lua, lua.h, does a very good job of avoiding namespace
pollution. Most of the identifiers start with lua or LUA which is an
entirely reasonable part of the namespace to grab. However...
The following code:
--
#define index 9
#include "lua.h"
/* ... */
--
won't compile. This is of course because inside lua.h their are
function declarations like:
LUA_API double lua_tonumber (lua_State *L, int index);
and the "index" identifier, sorry, pre-processor token, will get macro
substituted.
This is of course an unlikely state of affairs, but in the interests of
extreme cleanliness I think it would be nice if you avoided this sort of
namespace pollution as well.
What you need to do:
All preprocessor tokens that may be subject to macro substitution should
being with lua or LUA.
This includes:
- parameter names in function prototypes.
- structure member names.
For function prototypes you can simple omit the names (include them in
comments if you must).
Dealing with structure member names is more thorny because you have to
live with the tedious clean member names wherever you use the structure
(in ISO C up to 1999 you could have declared a parallel struct with nice
names and used that internally, the 1999 publication of the new C
standard now makes that an error).
Cheers,
drj