Thread overview | ||||||
---|---|---|---|---|---|---|
|
March 25, 2005 converting from macro to function | ||||
---|---|---|---|---|
| ||||
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! |
March 25, 2005 Re: converting from macro to function | ||||
---|---|---|---|---|
| ||||
Posted in reply to clayasaurus | > 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 |
March 25, 2005 Re: converting from macro to function | ||||
---|---|---|---|---|
| ||||
Posted in reply to clayasaurus | 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
|
March 25, 2005 Re: converting from macro to function | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ben Hinkle | 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 : )
|
Copyright © 1999-2021 by the D Language Foundation