[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Very small feature request
- From: "Joshua Jensen" <jjensen@...>
- Date: Wed, 9 Apr 2003 09:32:56 -0600
> >I believe that many C++ developers use lua these days.
> Although the lua
> >interpreter is written in C, it would be nice if the 3 main
> headers had
> >extern "C" declarations in them.
>
> This is a frequent request. However, Lua's implementation
> compiles under both C and C++. Adding extern "C" would force
> it to be a C library instead of a C++ library. --lhf
I had to do it via macros. There was an application we embedded Lua 5.0
in that had an old Lua 3.2 binding that couldn't be replaced. I had to
do the following:
#ifdef LUA_CPP_MODE
#define NAMESPACE_LUA_BEGIN namespace Lua {
#define NAMESPACE_LUA_END } // namespace Lua
#define USING_NAMESPACE_LUA using namespace Lua;
#define NAMESPACE_LUA_PREFIX Lua::
#define LUA_EXTERN_C
#define LUA_EXTERN_C_BEGIN
#define LUA_EXTERN_C_END
#else
#define NAMESPACE_LUA_BEGIN
#define NAMESPACE_LUA_END
#define USING_NAMESPACE_LUA
#define NAMESPACE_LUA_PREFIX
#define LUA_EXTERN_C extern "C"
#define LUA_EXTERN_C_BEGIN extern "C" {
#define LUA_EXTERN_C_END }
#endif LUA_CPP_MODE
I wrapped every Lua source and header file with NAMESPACE_LUA_BEGIN and
NAMESPACE_LUA_END. Then I used LUA_EXTERN_C* where appropriate. It
worked great. I'd highly recommend it.
Josh