lua-users home
lua-l archive

Re: Announcing: Luaxx 0.1, a C++ Lua wrapper

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


Jérôme VUARAND wrote:
2007年2月25日, Thomas Harning Jr. <harningt@gmail.com>:
On 2/25/07, Matthew A. Nicholson <matt@matt-land.com> wrote:
Great job on the library, however I think it could use a little fixing
for the 'as' function. Passing in a variable of the type in order to
get C++ to know what type to use doesn't sound like the best idea.
Using C++ templates seems to make the most sense to me.
Instead of:
int val = L.as(0, index);
It would be:
int val = L.as<int>(index);
... Just my 2 cents.
I was about to make the same suggestion. And if your original
intention was to write more generic code like :
int val;
val = L.as(val, index);
with a modern compiler you could write :
int val = L.as<typeof(val)>(index);
Not all compiler support the typeof operator yet, but GCC does and
template based limited implementations exist for those that don't.
The design for that function was taken from pqxx:
http://thaiopensource.org/devprojects/libpqxx/doc/2.6.8/html/Reference/
Looking at their docs, they use a template for it too (and have the option to specify a default value to return if the conversion fails). I will update it to match.
--
Matthew A. Nicholson
matt-land.com

AltStyle によって変換されたページ (->オリジナル) /