lua-users home
lua-l archive

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

i'm using lua as a dynamic link library under win32.
To build the dll i just use the unmodified lua headers files, but from the application, i don't need
the function definitions, but the function pointers that i'm going to map, so i need a different
header with the pointers. I need also the macros and the definitions that are in the original
headers, but i cannot include it because of name conflicts (the function definitions have the same
name as my function pointers). So i have to duplicate the headers, one with function definitions and
the other one with the function pointers.

I was wondering if there is a way of writting only one header file, with a macro that allows you to
declare the functions as pointers or as definitions. For example:

in lua.h:

#ifndef LUA_PROC
#define LUA_PROC( ret, func, params )  extern ret func params

and in you application:

extern "C" {
#define LUA_PROC(ret, func, param) extern ret (* func) param
    #include "lua.h"
#undef LUA_PROC

so to define lua_open you do:

LUA_PROC( lua_State *, lua_open, (int stacksize) );

it doesn't look very good, but works right.
However there are still problems, because function pointers are defined as extern to avoid multiple
definitions, so they have to be declared in a source file. To do that you just include the header
file from the source file doing:

extern "C" {
#define LUA_PROC(ret, func, param) ret (* func) param
    #include "lua.h"
#undef LUA_PROC

and everything works right. The LUA_PROC macro adds more versatility to the lua headers than the
LUA_API definition. I would really like to see this in future releases and I would appreciate some
comments and/or better ideas.

Ignacio Castano

Do You Yahoo!?
Get your free address at