lua-users home
lua-l archive

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


Hi, list!

The lrandom module as it is does not compiles as C++ code:

    lrandom.c: In function 'MT* Pget(lua_State*, int)':
    lrandom.c:25: error: invalid conversion from 'void*' to 'MT*'
    lrandom.c: In function 'MT* Pnew(lua_State*)':
    lrandom.c:30: error: invalid conversion from 'void*' to 'MT*'

Proposed patch below.

Alexander.

@@ -22,12 +22,12 @@

 static MT *Pget(lua_State *L, int i)
 {
- return luaL_checkudata(L,i,MYTYPE);
+ return (MT*)luaL_checkudata(L,i,MYTYPE);
 }

 static MT *Pnew(lua_State *L)
 {
- MT *c=lua_newuserdata(L,sizeof(MT));
+ MT *c=(MT*)lua_newuserdata(L,sizeof(MT));
  luaL_getmetatable(L,MYTYPE);
  lua_setmetatable(L,-2);
  return c;
@@ -108,6 +108,10 @@ static const luaL_reg R[] =
        { NULL,         NULL            }
 };

+#ifdef __cplusplus
+extern "C"
+{
+#endif // __cplusplus
 LUALIB_API int luaopen_random(lua_State *L)
 {
  luaL_newmetatable(L,MYTYPE);
@@ -122,3 +126,6 @@ LUALIB_API int luaopen_random(lua_State *L)
  lua_setglobal(L,MYNAME);
  return 1;
 }
+#ifdef __cplusplus
+}
+#endif // __cplusplus