digitalmars.D.learn - converting from macro to function
- clayasaurus <clayasaurus gmail.com> Mar 24 2005
- "Ben Hinkle" <ben.hinkle gmail.com> Mar 25 2005
- clayasaurus <clayasaurus gmail.com> Mar 25 2005
- "Regan Heath" <regan netwin.co.nz> Mar 25 2005
Hi all. I'm having trouble converting a couple of macros to a C or D
function, I guess my problem is I don't know exactly what types are
being passed to the macro or what it is really doing. Here is one of the
macro's
#define lua_boxpointer(L,u) (*(void **)(lua_newuserdata(L, sizeof(void
*))) = (u))
I know that L is of type lua_State*L, but I don't know what U is
supposed to be, or why you can do strange things with it like set it
equal to a function in a weird way. I think it is some sort of changable
data (it could be different types). Anyway, I've tried to convert it to
the following C function...
extern(C) {
void lua_boxpointer(lua_State *L, void ** u)
{
*(void**)lua_newuserdata(L, sizeof(void*)) = u; // line 3
}
}
and I get a million errors
lua.d(3): found '*' when expecting '.' following 'void'
lua.d(3): found ')' when expecting identifier following 'void.'
lua.d(3): found ';' when expecting ','
lua.d(4): expression expected, not '}'
I'm not sure if there is a better way to figure out how to get these
things implemented.
Anyway, any help would be greatly appreciated!
Mar 24 2005
extern(C) { void lua_boxpointer(lua_State *L, void ** u) { *(void**)lua_newuserdata(L, sizeof(void*)) = u; // line 3 }
try *cast(void**)lua_newuserdata(L, (void*).sizeof) = u; // line 3
Mar 25 2005
Ben Hinkle wrote:extern(C) { void lua_boxpointer(lua_State *L, void ** u) { *(void**)lua_newuserdata(L, sizeof(void*)) = u; // line 3 }
try *cast(void**)lua_newuserdata(L, (void*).sizeof) = u; // line 3
Thanks, that compiled : ) And hopefully works too : )
Mar 25 2005
On Fri, 25 Mar 2005 00:52:14 -0500, clayasaurus <clayasaurus gmail.com> wrote:Hi all. I'm having trouble converting a couple of macros to a C or D function, I guess my problem is I don't know exactly what types are being passed to the macro or what it is really doing. Here is one of the macro's #define lua_boxpointer(L,u) (*(void **)(lua_newuserdata(L, sizeof(void *))) = (u)) I know that L is of type lua_State*L, but I don't know what U is supposed to be, or why you can do strange things with it like set it equal to a function in a weird way. I think it is some sort of changable data (it could be different types). Anyway, I've tried to convert it to the following C function... extern(C) { void lua_boxpointer(lua_State *L, void ** u) { *(void**)lua_newuserdata(L, sizeof(void*)) = u; // line 3 } } and I get a million errors lua.d(3): found '*' when expecting '.' following 'void' lua.d(3): found ')' when expecting identifier following 'void.' lua.d(3): found ';' when expecting ',' lua.d(4): expression expected, not '}' I'm not sure if there is a better way to figure out how to get these things implemented. Anyway, any help would be greatly appreciated!
I'm not sure if this helps at all.. are you supposed to use C style or D style casts in an extern(C) block? Regan
Mar 25 2005









clayasaurus <clayasaurus gmail.com> 