www.digitalmars.com         C & C++   DMDScript  

D.gnu - Interesting error

reply daerid <daerid gmail.com> writes:
I'm trying to work with the lua D port at
http://svn.dsource.org/projects/bindings/trunk/lua/

And I ran into an interesting error:

"cannot implicitly convert expression (#luaopen_base) of type 
int(C *)(lua_State * L) to int(C *)(lua_State* L)"

When compiling this code:

-----------------------------------------------
import lua.lua;
import lua.lualib;
import lua.lauxlib;

int main(char[][] args)
{
lauL_reg lr;
lr.name = "base";
lr.func = &luaopen_base;
return 0;
}
-----------------------------------------------

Anybody have any idea what's going on here?

Bryan Ross
daerid gmail.com
Dec 22 2005
next sibling parent reply "Regan Heath" <regan netwin.co.nz> writes:
On Thu, 22 Dec 2005 10:11:03 +0000 (UTC), daerid <daerid gmail.com> wrote:
 I'm trying to work with the lua D port at
 http://svn.dsource.org/projects/bindings/trunk/lua/

 And I ran into an interesting error:

 "cannot implicitly convert expression (#luaopen_base) of type
 int(C *)(lua_State * L) to int(C *)(lua_State* L)"

 When compiling this code:

 -----------------------------------------------
 import lua.lua;
 import lua.lualib;
 import lua.lauxlib;

 int main(char[][] args)
 {
 lauL_reg lr;
 lr.name = "base";
 lr.func = &luaopen_base;
 return 0;
 }
 -----------------------------------------------

 Anybody have any idea what's going on here?

Can you post the definition of "lauL_reg" and "luaopen_base". I've seen an error like this when the "extern" type was different, perhaps that is the case here? Regan
Dec 22 2005
parent reply clayasaurus <clayasaurus gmail.com> writes:
Regan Heath wrote:
 On Thu, 22 Dec 2005 10:11:03 +0000 (UTC), daerid <daerid gmail.com> wrote:
 
 I'm trying to work with the lua D port at
 http://svn.dsource.org/projects/bindings/trunk/lua/

 And I ran into an interesting error:

 "cannot implicitly convert expression (#luaopen_base) of type
 int(C *)(lua_State * L) to int(C *)(lua_State* L)"

 When compiling this code:

 -----------------------------------------------
 import lua.lua;
 import lua.lualib;
 import lua.lauxlib;

 int main(char[][] args)
 {
 lauL_reg lr;
 lr.name = "base";
 lr.func = &luaopen_base;
 return 0;
 }
 -----------------------------------------------

 Anybody have any idea what's going on here?

Can you post the definition of "lauL_reg" and "luaopen_base". I've seen an error like this when the "extern" type was different, perhaps that is the case here? Regan

extern (C) { struct luaL_reg { const char *name; lua_CFunction func; }; int luaopen_base (lua_State *L); } Both are extern(C). I'll play around and see if I can re-create that error in a little bit.
Dec 22 2005
parent "Regan Heath" <regan netwin.co.nz> writes:
On Thu, 22 Dec 2005 15:59:20 -0500, clayasaurus <clayasaurus gmail.com>  
wrote:
 Regan Heath wrote:
 On Thu, 22 Dec 2005 10:11:03 +0000 (UTC), daerid <daerid gmail.com>  
 wrote:

 I'm trying to work with the lua D port at
 http://svn.dsource.org/projects/bindings/trunk/lua/

 And I ran into an interesting error:

 "cannot implicitly convert expression (#luaopen_base) of type
 int(C *)(lua_State * L) to int(C *)(lua_State* L)"

 When compiling this code:

 -----------------------------------------------
 import lua.lua;
 import lua.lualib;
 import lua.lauxlib;

 int main(char[][] args)
 {
 lauL_reg lr;
 lr.name = "base";
 lr.func = &luaopen_base;
 return 0;
 }
 -----------------------------------------------

 Anybody have any idea what's going on here?

seen an error like this when the "extern" type was different, perhaps that is the case here? Regan

extern (C) { struct luaL_reg { const char *name; lua_CFunction func; }; int luaopen_base (lua_State *L); } Both are extern(C).

And what about "lua_CFunction" :)
 I'll play around and see if I can re-create that error in a little bit.

Ok. Regan
Dec 22 2005
prev sibling parent reply clayasaurus <clayasaurus gmail.com> writes:
The problem seemed to be that lua_CFunction was defined as

alias int (*lua_CFunction) (lua_State *L);

The fix is to use stronger typing like

typedef int (*lua_CFunction) (lua_State *L);

I just commited new changes to the trunk which fix this problem. Update 
to that version and tell me if you are having any more problems. Thanks.

~ Clay

daerid wrote:
 I'm trying to work with the lua D port at
 http://svn.dsource.org/projects/bindings/trunk/lua/
 
 And I ran into an interesting error:
 
 "cannot implicitly convert expression (#luaopen_base) of type 
 int(C *)(lua_State * L) to int(C *)(lua_State* L)"
 
 When compiling this code:
 
 -----------------------------------------------
 import lua.lua;
 import lua.lualib;
 import lua.lauxlib;
 
 int main(char[][] args)
 {
 lauL_reg lr;
 lr.name = "base";
 lr.func = &luaopen_base;
 return 0;
 }
 -----------------------------------------------
 
 Anybody have any idea what's going on here?
 
 Bryan Ross
 daerid gmail.com

Dec 22 2005
parent reply daerid <daerid gmail.com> writes:
I also got this fixed by a different route. All the functions in lua.d are
declared like:

extern int lua_gettop (lua_State *L);

whereas luaopen_base is declared like so:

/*LUA_API*/ int luaopen_base (lua_State * L);

so I replaced all the /*LUA_API*/ entries with 'extern' and all was good in the
world.

In article <dof6qb$798$1 digitaldaemon.com>, clayasaurus says...
The problem seemed to be that lua_CFunction was defined as

alias int (*lua_CFunction) (lua_State *L);

The fix is to use stronger typing like

typedef int (*lua_CFunction) (lua_State *L);

I just commited new changes to the trunk which fix this problem. Update 
to that version and tell me if you are having any more problems. Thanks.

~ Clay

daerid wrote:
 I'm trying to work with the lua D port at
 http://svn.dsource.org/projects/bindings/trunk/lua/
 
 And I ran into an interesting error:
 
 "cannot implicitly convert expression (#luaopen_base) of type 
 int(C *)(lua_State * L) to int(C *)(lua_State* L)"
 
 When compiling this code:
 
 -----------------------------------------------
 import lua.lua;
 import lua.lualib;
 import lua.lauxlib;
 
 int main(char[][] args)
 {
 lauL_reg lr;
 lr.name = "base";
 lr.func = &luaopen_base;
 return 0;
 }
 -----------------------------------------------
 
 Anybody have any idea what's going on here?
 
 Bryan Ross
 daerid gmail.com


Dec 24 2005
parent reply "Kris" <fu bar.com> writes:
"daerid" <daerid gmail.com> wrote ...
I also got this fixed by a different route. All the functions in lua.d are
 declared like:

 extern int lua_gettop (lua_State *L);

 whereas luaopen_base is declared like so:

 /*LUA_API*/ int luaopen_base (lua_State * L);

 so I replaced all the /*LUA_API*/ entries with 'extern' and all was good 
 in the
 world.

Sigh ... gotta' love that :-)
Dec 24 2005
parent daerid <daerid gmail.com> writes:
I know. You'd think that the compiler would be smart enough to realize that a
function declared (and 
not defined) inside an extern (C) block would be 'extern'.

Also, IMO, extern is a storage-class identifier, isn't it? It shouldn't affect
type resolution. Especially 
when it produces messages like: "Could not implicitly cast from type T to T"
where both types are 
reportedly identical.

Just a thought

In article <dol316$25jd$1 digitaldaemon.com>, Kris says...
"daerid" <daerid gmail.com> wrote ...
I also got this fixed by a different route. All the functions in lua.d are
 declared like:

 extern int lua_gettop (lua_State *L);

 whereas luaopen_base is declared like so:

 /*LUA_API*/ int luaopen_base (lua_State * L);

 so I replaced all the /*LUA_API*/ entries with 'extern' and all was good 
 in the
 world.

Sigh ... gotta' love that :-)

Dec 25 2005