[Yake-svn] SF.net SVN: yake: [1873] trunk/yake
Status: Beta
Brought to you by:
psyclonist
From: <psy...@us...> - 2007-09-18 00:26:38
|
Revision: 1873 http://yake.svn.sourceforge.net/yake/?rev=1873&view=rev Author: psyclonist Date: 2007-09-17 17:26:38 -0700 (Mon, 17 Sep 2007) Log Message: ----------- * [bindings.lua] fixed issue caused by Luabind in conjunction with GCC and any_converters: solution is the same as with the shared_ptr fix. -> task.lua.cpp for details. Modified Paths: -------------- trunk/yake/scripts/premake/config.lua trunk/yake/src/bindings.lua/bindings.lua.cpp trunk/yake/src/bindings.lua/detail/base.lua.cpp trunk/yake/src/bindings.lua/detail/ent.listener.lua.cpp trunk/yake/src/bindings.lua/detail/ent.registry.lua.cpp trunk/yake/src/bindings.lua/detail/graphics.lua.cpp trunk/yake/src/bindings.lua/detail/input.lua.cpp trunk/yake/src/bindings.lua/detail/model.lua.cpp trunk/yake/src/bindings.lua/detail/physics.lua.cpp trunk/yake/src/bindings.lua/detail/property.lua.cpp trunk/yake/src/bindings.lua/detail/raf.lua.cpp trunk/yake/src/bindings.lua/detail/res.lua.cpp trunk/yake/src/bindings.lua/detail/task.lua.cpp trunk/yake/yake/bindings.lua/common/vminfo.lua.cpp trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h trunk/yake/yake/bindings.lua/detail/property.lua.h Added Paths: ----------- trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.inl Modified: trunk/yake/scripts/premake/config.lua =================================================================== --- trunk/yake/scripts/premake/config.lua 2007-09-18 00:21:13 UTC (rev 1872) +++ trunk/yake/scripts/premake/config.lua 2007-09-18 00:26:38 UTC (rev 1873) @@ -28,7 +28,7 @@ -- Plugins -------------------------------------- --- NB only some of these are implemented: +-- NB only some of these options have effect --PLUGIN_SCRIPTING_LUA = true PLUGIN_AUDIO_OPENAL = true PLUGIN_GRAPHICS_OGRE = true Modified: trunk/yake/src/bindings.lua/bindings.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/bindings.lua.cpp 2007-09-18 00:21:13 UTC (rev 1872) +++ trunk/yake/src/bindings.lua/bindings.lua.cpp 2007-09-18 00:26:38 UTC (rev 1873) @@ -28,15 +28,22 @@ #include <yake/scripting/yakeScriptingSystem.h> #include <yake/plugins/scriptingLua/ScriptingSystemLua.h> #include <yake/bindings.lua/bindings.lua.h> + +#define YAKE_EXPORT_LUA_ANY_CONVERTER +// The order of the following 4 includes is very important! +// -> see task.cpp for more information! +#include <yake/bindings.lua/common/yake.lua.shared_ptr.h> +#include <yake/bindings.lua/common/yake.lua.any_converter.h> #include <yake/bindings.lua/common/yake.lua.common.h> +#include <yake/bindings.lua/common/yake.lua.any_converter.inl> +// +#include <yake/bindings.lua/common/yake.lua.any_converter.cpp> + +// #include <yake/bindings.lua/common/lua.helpers.h> #include <yake/bindings.lua/common/lua.helpers.cpp> // define here -#define YAKE_EXPORT_LUA_ANY_CONVERTER -#include <yake/bindings.lua/common/yake.lua.any_converter.h> -#include <yake/bindings.lua/common/yake.lua.any_converter.cpp> - namespace yake { namespace { struct RegisterDefaultAnyConverters @@ -48,11 +55,11 @@ register_any_converter<double>(); register_any_converter<bool>(); register_any_converter<String>(); - + register_any_converter<luabind::object>(); } } g_registerDefaultAnyConverters; - } // namespace + } // namespace void bind_all(lua_State* L) { Modified: trunk/yake/src/bindings.lua/detail/base.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/base.lua.cpp 2007-09-18 00:21:13 UTC (rev 1872) +++ trunk/yake/src/bindings.lua/detail/base.lua.cpp 2007-09-18 00:26:38 UTC (rev 1873) @@ -29,13 +29,16 @@ #include <yake/base/yake.h> -#include <yake/bindings.lua/bindings.lua.h> // Don't forget to include this for proper dllexport! +// The order of the following 4 includes is very important! +// -> see task.cpp for more information! +#include <yake/bindings.lua/common/yake.lua.shared_ptr.h> +#include <yake/bindings.lua/common/yake.lua.any_converter.h> +#include <yake/bindings.lua/common/yake.lua.common.h> +#include <yake/bindings.lua/common/yake.lua.any_converter.inl> #include <yake/bindings.lua/detail/private.h> #include <yake/bindings.lua/common/lua.helpers.h> #include <yake/bindings.lua/common/vminfo.lua.h> -#include <yake/bindings.lua/common/yake.lua.shared_ptr.h> -#include <yake/bindings.lua/common/yake.lua.any_converter.h> #include <luabind/operator.hpp> #include <luabind/adopt_policy.hpp> Modified: trunk/yake/src/bindings.lua/detail/ent.listener.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/ent.listener.lua.cpp 2007-09-18 00:21:13 UTC (rev 1872) +++ trunk/yake/src/bindings.lua/detail/ent.listener.lua.cpp 2007-09-18 00:26:38 UTC (rev 1873) @@ -27,14 +27,18 @@ #include <yake/config.h> #if YAKE_ENABLE_LUA_ENT == 1 -#include <yake/bindings.lua/bindings.lua.h> // Don't forget to include this for proper dllexport! +// The order of the following 4 includes is very important! +// -> see task.cpp for more information! +#include <yake/bindings.lua/common/yake.lua.shared_ptr.h> +#include <yake/bindings.lua/common/yake.lua.any_converter.h> +#include <yake/bindings.lua/common/yake.lua.common.h> +#include <yake/bindings.lua/common/yake.lua.any_converter.inl> +// #include <yake/base/templates/yakeSmartAssert.h> #include <yake/bindings.lua/bindings.lua.ent.h> #include <yake/bindings.lua/bindings.lua.ent.registry.h> -#include <yake/bindings.lua/common/yake.lua.shared_ptr.h> -#include <yake/bindings.lua/common/yake.lua.any_converter.h> #include <yake/bindings.lua/detail/private.h> #include <yake/bindings.lua/detail/property.lua.h> Modified: trunk/yake/src/bindings.lua/detail/ent.registry.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/ent.registry.lua.cpp 2007-09-18 00:21:13 UTC (rev 1872) +++ trunk/yake/src/bindings.lua/detail/ent.registry.lua.cpp 2007-09-18 00:26:38 UTC (rev 1873) @@ -27,12 +27,13 @@ #include <yake/config.h> #if YAKE_ENABLE_LUA_ENT == 1 +#include <yake/bindings.lua/common/yake.lua.shared_ptr.h> // Always before Luabind includes! + #include <yake/bindings.lua/bindings.lua.h> // Don't forget to include this for proper dllexport! #include <yake/base/templates/yakeSmartAssert.h> #include <yake/bindings.lua/bindings.lua.ent.registry.h> -#include <yake/bindings.lua/common/yake.lua.shared_ptr.h> #include <yake/bindings.lua/detail/private.h> namespace yake { Modified: trunk/yake/src/bindings.lua/detail/graphics.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/graphics.lua.cpp 2007-09-18 00:21:13 UTC (rev 1872) +++ trunk/yake/src/bindings.lua/detail/graphics.lua.cpp 2007-09-18 00:26:38 UTC (rev 1873) @@ -29,11 +29,17 @@ #define YAKE_ENABLE_LUA_GRAPHICS_OGRE 0 #if YAKE_ENABLE_LUA_GRAPHICS == 1 +#include <yake/bindings.lua/prerequisites.h> // Don't forget to include this for proper dllexport! + // See task.lua.cpp +// The order of the following 4 includes is very important! +// -> see task.cpp for more information! #include <yake/bindings.lua/common/yake.lua.shared_ptr.h> +#include <yake/bindings.lua/common/yake.lua.any_converter.h> +#include <yake/bindings.lua/common/yake.lua.common.h> +#include <yake/bindings.lua/common/yake.lua.any_converter.inl> -#include <yake/bindings.lua/bindings.lua.h> // Don't forget to include this for proper dllexport! - +// #include <yake/base/templates/yakeSmartAssert.h> #include <yake/base/yake.h> #include <yake/graphics/yakeGraphics.h> @@ -49,7 +55,6 @@ #endif #include <yake/bindings.lua/detail/private.h> -#include <yake/bindings.lua/common/yake.lua.any_converter.h> #include <luabind/discard_result_policy.hpp> #include <luabind/iterator_policy.hpp> Modified: trunk/yake/src/bindings.lua/detail/input.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/input.lua.cpp 2007-09-18 00:21:13 UTC (rev 1872) +++ trunk/yake/src/bindings.lua/detail/input.lua.cpp 2007-09-18 00:26:38 UTC (rev 1873) @@ -27,17 +27,20 @@ #include <yake/config.h> #if YAKE_ENABLE_LUA_INPUT == 1 -// See task.lua.cpp +// The order of the following 4 includes is very important! +// -> see task.cpp for more information! #include <yake/bindings.lua/common/yake.lua.shared_ptr.h> +#include <yake/bindings.lua/common/yake.lua.any_converter.h> +#include <yake/bindings.lua/common/yake.lua.common.h> +#include <yake/bindings.lua/common/yake.lua.any_converter.inl> -#include <yake/bindings.lua/bindings.lua.h> // Don't forget to include this for proper dllexport! +// #include <yake/base/templates/yakeSmartAssert.h> #include <yake/base/yake.h> #include <yake/input/yakeInput.h> #include <yake/bindings.lua/detail/private.h> -#include <yake/bindings.lua/common/yake.lua.any_converter.h> #include <luabind/discard_result_policy.hpp> #include <luabind/iterator_policy.hpp> Modified: trunk/yake/src/bindings.lua/detail/model.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/model.lua.cpp 2007-09-18 00:21:13 UTC (rev 1872) +++ trunk/yake/src/bindings.lua/detail/model.lua.cpp 2007-09-18 00:26:38 UTC (rev 1873) @@ -27,13 +27,17 @@ #include <yake/config.h> #if YAKE_ENABLE_LUA_MODEL == 1 -#include <yake/bindings.lua/bindings.lua.h> // Don't forget to include this for proper dllexport! +// The order of the following 4 includes is very important! +// -> see task.cpp for more information! +#include <yake/bindings.lua/common/yake.lua.shared_ptr.h> +#include <yake/bindings.lua/common/yake.lua.any_converter.h> +#include <yake/bindings.lua/common/yake.lua.common.h> +#include <yake/bindings.lua/common/yake.lua.any_converter.inl> +// #include <yake/base/templates/yakeSmartAssert.h> #include <yake/base/yake.h> #include <yake/model/model.h> -#include <yake/bindings.lua/common/yake.lua.shared_ptr.h> -#include <yake/bindings.lua/common/yake.lua.any_converter.h> #include <yake/bindings.lua/detail/private.h> #include <luabind/discard_result_policy.hpp> Modified: trunk/yake/src/bindings.lua/detail/physics.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/physics.lua.cpp 2007-09-18 00:21:13 UTC (rev 1872) +++ trunk/yake/src/bindings.lua/detail/physics.lua.cpp 2007-09-18 00:26:38 UTC (rev 1873) @@ -29,17 +29,19 @@ #pragma warning(disable:4267) // VC8-32Bit: conversion from 'size_t' to 'unsigned int', possible loss of data -// See task.lua.cpp +// The order of the following 4 includes is very important! +// -> see task.cpp for more information! #include <yake/bindings.lua/common/yake.lua.shared_ptr.h> +#include <yake/bindings.lua/common/yake.lua.any_converter.h> +#include <yake/bindings.lua/common/yake.lua.common.h> +#include <yake/bindings.lua/common/yake.lua.any_converter.inl> -#include <yake/bindings.lua/bindings.lua.h> // Don't forget to include this for proper dllexport! - +// #include <yake/base/templates/yakeSmartAssert.h> #include <yake/base/yake.h> #include <yake/physics/yakePhysics.h> #include <yake/bindings.lua/detail/private.h> -#include <yake/bindings.lua/common/yake.lua.any_converter.h> #include <luabind/discard_result_policy.hpp> #include <luabind/iterator_policy.hpp> Modified: trunk/yake/src/bindings.lua/detail/property.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/property.lua.cpp 2007-09-18 00:21:13 UTC (rev 1872) +++ trunk/yake/src/bindings.lua/detail/property.lua.cpp 2007-09-18 00:26:38 UTC (rev 1873) @@ -27,15 +27,17 @@ #include <yake/config.h> #if YAKE_ENABLE_LUA_PROPERTY == 1 +// The order of the following 4 includes is very important! +// -> see task.cpp for more information! #include <yake/bindings.lua/common/yake.lua.shared_ptr.h> +#include <yake/bindings.lua/common/yake.lua.any_converter.h> +#include <yake/bindings.lua/common/yake.lua.common.h> +#include <yake/bindings.lua/common/yake.lua.any_converter.inl> -#include <yake/bindings.lua/bindings.lua.h> // Don't forget to include this for proper dllexport! - #include <yake/base/templates/yakeSmartAssert.h> #include <yake/base/yake.h> #include <yake/property/property.h> -#include <yake/bindings.lua/common/yake.lua.any_converter.h> #include <yake/bindings.lua/detail/private.h> #include <yake/bindings.lua/detail/property.lua.h> Modified: trunk/yake/src/bindings.lua/detail/raf.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/raf.lua.cpp 2007-09-18 00:21:13 UTC (rev 1872) +++ trunk/yake/src/bindings.lua/detail/raf.lua.cpp 2007-09-18 00:26:38 UTC (rev 1873) @@ -30,13 +30,18 @@ #include <yake/base/yake.h> #include <yake/raf/yakeRaf.h> -#include <yake/bindings.lua/bindings.lua.h> // Don't forget to include this for proper dllexport! +// The order of the following 4 includes is very important! +// -> see task.cpp for more information! +#include <yake/bindings.lua/common/yake.lua.shared_ptr.h> +#include <yake/bindings.lua/common/yake.lua.any_converter.h> +#include <yake/bindings.lua/common/yake.lua.common.h> +#include <yake/bindings.lua/common/yake.lua.any_converter.inl> +// + #include <yake/bindings.lua/detail/private.h> #include <yake/bindings.lua/common/lua.helpers.h> #include <yake/bindings.lua/common/vminfo.lua.h> -#include <yake/bindings.lua/common/yake.lua.shared_ptr.h> -#include <yake/bindings.lua/common/yake.lua.any_converter.h> namespace yake { namespace raf { @@ -54,7 +59,7 @@ } */ } g_initer; - } // namespace + } // namespace input::KeyboardDevice* getAppKeyboard(raf::Application* app) { return app ? app->getKeyboard() : 0; Modified: trunk/yake/src/bindings.lua/detail/res.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/res.lua.cpp 2007-09-18 00:21:13 UTC (rev 1872) +++ trunk/yake/src/bindings.lua/detail/res.lua.cpp 2007-09-18 00:26:38 UTC (rev 1873) @@ -28,16 +28,20 @@ #if YAKE_ENABLE_LUA_RES == 1 // See task.lua.cpp +// The order of the following 4 includes is very important! +// -> see task.cpp for more information! #include <yake/bindings.lua/common/yake.lua.shared_ptr.h> +#include <yake/bindings.lua/common/yake.lua.any_converter.h> +#include <yake/bindings.lua/common/yake.lua.common.h> +#include <yake/bindings.lua/common/yake.lua.any_converter.inl> -#include <yake/bindings.lua/bindings.lua.h> // Don't forget to include this for proper dllexport! +// #include <yake/base/templates/yakeSmartAssert.h> #include <yake/base/yake.h> #include <yake/res/res.h> #include <yake/bindings.lua/detail/private.h> -#include <yake/bindings.lua/common/yake.lua.any_converter.h> #include <luabind/discard_result_policy.hpp> #include <luabind/iterator_policy.hpp> Modified: trunk/yake/src/bindings.lua/detail/task.lua.cpp =================================================================== --- trunk/yake/src/bindings.lua/detail/task.lua.cpp 2007-09-18 00:21:13 UTC (rev 1872) +++ trunk/yake/src/bindings.lua/detail/task.lua.cpp 2007-09-18 00:26:38 UTC (rev 1873) @@ -39,16 +39,20 @@ // luabind::get_const_holder(...) catch all handler. // (Source: http://osdir.com/ml/lang.lua.bind.user/2006-02/msg00008.html) // Solution: Include the overloads for our smart pointers PRIOR to any Luabind headers. +// +// Update: Also do the same for any_converters because of is_userdefined(...). +// #include <yake/bindings.lua/common/yake.lua.shared_ptr.h> +#include <yake/bindings.lua/common/yake.lua.any_converter.h> +#include <yake/bindings.lua/common/yake.lua.common.h> +#include <yake/bindings.lua/common/yake.lua.any_converter.inl> -#include <yake/bindings.lua/bindings.lua.h> // Don't forget to include this for proper dllexport! - +// #include <yake/base/templates/yakeSmartAssert.h> #include <yake/bindings.lua/detail/private.h> #include <yake/bindings.lua/common/lua.helpers.h> #include <yake/bindings.lua/common/vminfo.lua.h> -#include <yake/bindings.lua/common/yake.lua.any_converter.h> #include <yake/task/task.h> Modified: trunk/yake/yake/bindings.lua/common/vminfo.lua.cpp =================================================================== --- trunk/yake/yake/bindings.lua/common/vminfo.lua.cpp 2007-09-18 00:21:13 UTC (rev 1872) +++ trunk/yake/yake/bindings.lua/common/vminfo.lua.cpp 2007-09-18 00:26:38 UTC (rev 1873) @@ -28,19 +28,19 @@ #include "vminfo.lua.h" // Lua and Luabind includes: -extern "C" { +//extern "C" { #include "lua.h" #include "lualib.h" #include "lauxlib.h" -} +//} #pragma warning(push) #pragma warning(disable: 4251) #include <luabind/luabind.hpp> #pragma warning(pop) // @todo autolink? -#pragma comment(lib,"luad.lib") -#pragma comment(lib,"luabindd.lib") +//#pragma comment(lib,"luad.lib") +//#pragma comment(lib,"luabindd.lib") // namespace yake { Modified: trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h =================================================================== --- trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h 2007-09-18 00:21:13 UTC (rev 1872) +++ trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.h 2007-09-18 00:26:38 UTC (rev 1873) @@ -31,10 +31,23 @@ #include <yake/base/yakePrerequisites.h> #include <yake/base/type_info.h> #include <yake/bindings.lua/prerequisites.h> -#include <yake/bindings.lua/common/yake.lua.common.h> +//#include <yake/bindings.lua/common/yake.lua.common.h> #include <map> #include <boost/any.hpp> +#include <luabind/detail/yes_no.hpp> // safe. doesn't include luabind/detail/policy.hpp +#include <luabind/detail/primitives.hpp> +struct lua_State; +namespace luabind { + namespace adl { class object; } + using adl::object; +} + +//================ FIXME ========================= +//#undef YAKE_ENABLE_LUA_PROPERTY +//#define YAKE_ENABLE_LUA_PROPERTY 0 +//================ FIXME ========================= + #define YAKE_LUA_ANY_CONVERTER_API YAKE_BINDINGS_LUA_API #define YAKE_LUA_ANY_CONVERTER_POINTERS 0 @@ -53,28 +66,15 @@ typedef std::map<TypeInfo,PropertyFromObjectFn> PropertyFromObjectMap; YAKE_LUA_ANY_CONVERTER_API PropertyFromObjectMap& object_property_creators(); - typedef luabind::class_<PropertyBase> LuabindClass_PropertyBase; - //typedef luabind::class_<PropertyBase,PropertyPtr> LuabindClass_PropertyBase; - - typedef void(*BindSetPropertyFn)(LuabindClass_PropertyBase&); + //typedef luabind::class_<PropertyBase> LuabindClass_PropertyBase; + typedef void* LuabindClass_PropertyBasePtr; + + typedef void(*BindSetPropertyFn)(LuabindClass_PropertyBasePtr); typedef std::vector<BindSetPropertyFn> BindSetPropertyFnList; YAKE_LUA_ANY_CONVERTER_API BindSetPropertyFnList& setPropertyValue_binders(); template<typename T> - bool setPropertyValue_Generic(PropertyBase& prop, const T& value) - { - try { - prop.setAny( value ); - return true; - } - catch (BadCastException&) - { - //@todo report error! throw exception? - std::cerr << ">>> Warning: Type mismatch on setting of property value!\n"; - std::cerr << " value type=" << typeid(T).name() << " expected type=" << prop.type() << "\n"; - return false; - } - } + bool setPropertyValue_Generic(PropertyBase& prop, const T& value); } // namespace property } // namespace yake #endif @@ -91,91 +91,14 @@ template<class T> struct convert_any { - static void convert(lua_State* L, const boost::any& a) - { - //typename luabind::detail::default_policy::template generate_converter<T, luabind::detail::cpp_to_lua>::type conv; - //conv.apply(L, *boost::any_cast<T>(&a)); - luabind::detail::convert_to_lua(L, *boost::any_cast<T>(&a)); - } + static void convert(lua_State* L, const boost::any& a); #if YAKE_ENABLE_LUA_PROPERTY == 1 // extension for yake::property: - static yake::property::PropertyBase* yake_createValuePropertyFromAny(const boost::any& a) - { - try - { - yake::property::Property<T>* prop = yake::property::makeValueProperty<T>( boost::any_cast<T>(a) ); - YAKE_ASSERT( prop ); - return prop; - } - catch (boost::bad_any_cast&) - { - return 0;//@todo report error - } - } - static yake::property::PropertyBase* yake_createValuePropertyFromObject(const luabind::object& a) - { - //int type = luabind::type(a); - boost::optional<T> value = luabind::object_cast_nothrow<T>(a); - if (value) - { - yake::property::Property<T>* prop = yake::property::makeValueProperty<T>( *value ); - YAKE_ASSERT( prop ); - return prop; - } -#if YAKE_LUA_ANY_CONVERTER_POINTERS == 1 - boost::optional<T*> valuePtr = luabind::object_cast_nothrow<T*>(a); - if (valuePtr) - { - T* px = *valuePtr; - if (px) - { - //yake::property::Property<T>* prop = yake::property::makeValueProperty<T>( *px ); - yake::property::Property<T>* prop = yake::property::makePointerProperty<T>( px ); - YAKE_ASSERT( prop ); - return prop; - } - } + static yake::property::PropertyBase* yake_createValuePropertyFromAny(const boost::any& a); + static yake::property::PropertyBase* yake_createValuePropertyFromObject(const luabind::object& a); + static void yake_bind_setPropertyValue(::yake::property::LuabindClass_PropertyBasePtr); #endif - return 0; //@todo report error - } - static void yake_bind_setPropertyValue(::yake::property::LuabindClass_PropertyBase& x) - { - x.def("set",&yake::property::setPropertyValue_Generic<T>); - } -#endif - static bool yake_anyFromObject(const luabind::object& a, boost::any& out) - { - boost::optional<T> value = luabind::object_cast_nothrow<T>(a); - if (value) - { - out = *value; - return true; - } -#if YAKE_LUA_ANY_CONVERTER_POINTERS == 1 - boost::optional<T*> valuePtr = luabind::object_cast_nothrow<T*>(a); - if (valuePtr) - { - T* px = *valuePtr; - if (px) - { - out = *px; - return true; - } - } -#endif - return false; //@todo report error ? - } - static bool yake_tryAnyFromObject(const luabind::object& a) - { - boost::optional<T> value = luabind::object_cast_nothrow<T>(a); - if (value) - return true; -#if YAKE_LUA_ANY_CONVERTER_POINTERS == 1 - boost::optional<T*> valuePtr = luabind::object_cast_nothrow<T*>(a); - if (value) - return true; -#endif - return false; //@todo report error ? - } + static bool yake_anyFromObject(const luabind::object& a, boost::any& out); + static bool yake_tryAnyFromObject(const luabind::object& a); }; typedef std::map<yake::TypeInfo, void(*)(lua_State*, const boost::any&)> any_converter_map; @@ -211,21 +134,18 @@ // This creator is to be used as a last resort only. If it is stored // with all the other creators it may get called before a better option // can be called. - template<> - inline void register_any_converter<luabind::object>() - { - const yake::TypeInfo ti = YAKE_TYPEID(luabind::object); - any_converters()[ti] = convert_any<luabind::object>::convert; -#if YAKE_ENABLE_LUA_PROPERTY == 1 // extension for yake::property: - yake::property::any_property_creators()[ti] = convert_any<luabind::object>::yake_createValuePropertyFromAny; - yake::property::setPropertyValue_binders().push_back( convert_any<luabind::object>::yake_bind_setPropertyValue ); -#endif - } + //template<> + //inline void register_any_converter<luabind::object>(); namespace luabind { namespace converters { + using luabind::detail::yes_t; + using luabind::detail::no_t; + using luabind::detail::by_value; + using luabind::detail::by_const_reference; + yes_t is_user_defined(by_value<boost::any>); yes_t is_user_defined(by_const_reference<boost::any>); Added: trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.inl =================================================================== --- trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.inl (rev 0) +++ trunk/yake/yake/bindings.lua/common/yake.lua.any_converter.inl 2007-09-18 00:26:38 UTC (rev 1873) @@ -0,0 +1,164 @@ +/* + ------------------------------------------------------------------------------------ + This file is part of YAKE + Copyright (c) 2004 - 2008 The YAKE Team + For the latest information visit http://www.yake.org + ------------------------------------------------------------------------------------ + This program is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free Software + Foundation; either version 2 of the License, or (at your option) any later + version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with + this program; if not, write to the Free Software Foundation, Inc., 59 Temple + Place - Suite 330, Boston, MA 02111-1307, USA, or go to + http://www.gnu.org/copyleft/lesser.txt. + ------------------------------------------------------------------------------------ + If you are interested in another license model contact the Yake Team via + E-Mail: te...@ya.... + For more information see the LICENSE file in the root directory of the + source code distribution. + ------------------------------------------------------------------------------------ +*/ +#ifndef YAKE_LUA_ANYCONVERTER_INL_H +#define YAKE_LUA_ANYCONVERTER_INL_H + +#if YAKE_ENABLE_LUA_PROPERTY == 1 // extension for yake::property: + namespace yake { + namespace property { + typedef luabind::class_<PropertyBase> LuabindClass_PropertyBase; + + template<typename T> + bool setPropertyValue_Generic(PropertyBase& prop, const T& value) + { + try { + prop.setAny( value ); + return true; + } + catch (BadCastException&) + { + //@todo report error! throw exception? + std::cerr << ">>> Warning: Type mismatch on setting of property value!\n"; + std::cerr << " value type=" << typeid(T).name() << " expected type=" << prop.type() << "\n"; + return false; + } + } + } // namespace property + } // namespace yake +#endif + + + // boost::any bindings + template<class T> + void convert_any<T>::convert(lua_State* L, const boost::any& a) + { + luabind::detail::convert_to_lua(L, *boost::any_cast<T>(&a)); + } +#if YAKE_ENABLE_LUA_PROPERTY == 1 // extension for yake::property: + template<class T> + yake::property::PropertyBase* convert_any<T>::yake_createValuePropertyFromAny(const boost::any& a) + { + try + { + yake::property::Property<T>* prop = yake::property::makeValueProperty<T>( boost::any_cast<T>(a) ); + YAKE_ASSERT( prop ); + return prop; + } + catch (boost::bad_any_cast&) + { + return 0;//@todo report error + } + } + template<class T> + yake::property::PropertyBase* convert_any<T>::yake_createValuePropertyFromObject(const luabind::object& a) + { + //int type = luabind::type(a); + boost::optional<T> value = luabind::object_cast_nothrow<T>(a); + if (value) + { + yake::property::Property<T>* prop = yake::property::makeValueProperty<T>( *value ); + YAKE_ASSERT( prop ); + return prop; + } +#if YAKE_LUA_ANY_CONVERTER_POINTERS == 1 + boost::optional<T*> valuePtr = luabind::object_cast_nothrow<T*>(a); + if (valuePtr) + { + T* px = *valuePtr; + if (px) + { + //yake::property::Property<T>* prop = yake::property::makeValueProperty<T>( *px ); + yake::property::Property<T>* prop = yake::property::makePointerProperty<T>( px ); + YAKE_ASSERT( prop ); + return prop; + } + } +#endif + return 0; //@todo report error + } + template<class T> + void convert_any<T>::yake_bind_setPropertyValue(::yake::property::LuabindClass_PropertyBasePtr xp) + { + yake::property::LuabindClass_PropertyBase& x = *reinterpret_cast<yake::property::LuabindClass_PropertyBase*>(xp); + x.def("set",&yake::property::setPropertyValue_Generic<T>); + } +#endif + template<class T> + bool convert_any<T>::yake_anyFromObject(const luabind::object& a, boost::any& out) + { + boost::optional<T> value = luabind::object_cast_nothrow<T>(a); + if (value) + { + out = *value; + return true; + } +#if YAKE_LUA_ANY_CONVERTER_POINTERS == 1 + boost::optional<T*> valuePtr = luabind::object_cast_nothrow<T*>(a); + if (valuePtr) + { + T* px = *valuePtr; + if (px) + { + out = *px; + return true; + } + } +#endif + return false; //@todo report error ? + } + template<class T> + bool convert_any<T>::yake_tryAnyFromObject(const luabind::object& a) + { + boost::optional<T> value = luabind::object_cast_nothrow<T>(a); + if (value) + return true; +#if YAKE_LUA_ANY_CONVERTER_POINTERS == 1 + boost::optional<T*> valuePtr = luabind::object_cast_nothrow<T*>(a); + if (value) + return true; +#endif + return false; //@todo report error ? + } + + // NB The specialization for luabind::object is required as for + // this type we do not store a creator in object_property_creators(). + // This creator is to be used as a last resort only. If it is stored + // with all the other creators it may get called before a better option + // can be called. + template<> + inline void register_any_converter<luabind::object>() + { + const yake::TypeInfo ti = YAKE_TYPEID(luabind::object); + any_converters()[ti] = convert_any<luabind::object>::convert; +#if YAKE_ENABLE_LUA_PROPERTY == 1 // extension for yake::property: + yake::property::any_property_creators()[ti] = convert_any<luabind::object>::yake_createValuePropertyFromAny; + yake::property::setPropertyValue_binders().push_back( convert_any<luabind::object>::yake_bind_setPropertyValue ); +#endif + } + + +#endif Modified: trunk/yake/yake/bindings.lua/detail/property.lua.h =================================================================== --- trunk/yake/yake/bindings.lua/detail/property.lua.h 2007-09-18 00:21:13 UTC (rev 1872) +++ trunk/yake/yake/bindings.lua/detail/property.lua.h 2007-09-18 00:26:38 UTC (rev 1873) @@ -24,13 +24,13 @@ source code distribution. ------------------------------------------------------------------------------------ */ -#ifndef YAKE_LUA_BINDINGS_PROPERTYLUA_H -#define YAKE_LUA_BINDINGS_PROPERTYLUA_H +#ifndef YAKE_LUA_BINDINGS_PROPERTYLUA__H +#define YAKE_LUA_BINDINGS_PROPERTYLUA__H #include <yake/config.h> #if YAKE_ENABLE_LUA_PROPERTY == 1 -#include <yake/bindings.lua/bindings.lua.h> // Don't forget to include this for proper dllexport! +#include <yake/bindings.lua/prerequisites.h> // Don't forget to include this for proper dllexport! #include <yake/base/yake.h> #include <yake/property/property.h> #include <boost/any.hpp> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |