[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua 5.2.1 (work1) now available
- From: Patrick Rapin <toupie300@...>
- Date: Sat, 7 Apr 2012 17:24:09 +0200
Small notes on C++ syntax:
> int factory(lua_State* L)
> {
> T* object = new (reinterpret_cast<T*>(lua_newuserdata(L, sizeof(T)))) T;
> /* set metatable here */
> return 1;
> }
The cast is useless here. The following form would work too :
T* object = new (lua_newuserdata(L, sizeof(T))) T;
> int gc_metamethod(lua_State* L)
> {
> T* object = reinterpret_cast<T*>(lua_touserdata(L, 1));
> object->~T();
> return 0;
> }
It would be better to use static_cast.
This is a essentially a matter of taste, but static_cast is for
regular (mostly safe) casts, const_cast to work around when an API
does not respect correct constness, dynamic_cast to try types at
runtime, and reinterpret_cast is for "hacks". When I see it, it
triggers this thought : "Hey, there is something tricky going on
here".
- References:
- Re: [ANN] Lua 5.2.1 (work1) now available, Miles Bader
- Re: [ANN] Lua 5.2.1 (work1) now available, Roberto Ierusalimschy
- Re: [ANN] Lua 5.2.1 (work1) now available, Miles Bader
- Re: [ANN] Lua 5.2.1 (work1) now available, Roberto Ierusalimschy
- Re: [ANN] Lua 5.2.1 (work1) now available, Miles Bader
- Re: [ANN] Lua 5.2.1 (work1) now available, Miles Bader
- Re: [ANN] Lua 5.2.1 (work1) now available, Roberto Ierusalimschy
- Re: [ANN] Lua 5.2.1 (work1) now available, Miles Bader
- Re: [ANN] Lua 5.2.1 (work1) now available, Miles Bader
- Re: [ANN] Lua 5.2.1 (work1) now available, Rena
- Re: [ANN] Lua 5.2.1 (work1) now available, Miles Bader
- Re: [ANN] Lua 5.2.1 (work1) now available, Coda Highland
- Re: [ANN] Lua 5.2.1 (work1) now available, Peter Cawley