Tomasu / LuaGlue

C++11 Lua 5.2 Binding Library
zlib License
79 stars 22 forks source link

VS2013 support #1

Closed JMLX42 closed 10 years ago

JMLX42 commented 10 years ago

Hello,

I'm working on a C++ port of Minko (http://minko.io), a 3D engine for the web and mobile devices. I'm working on embedding the LUA VM to have a scripting system.

My scripts need to have access to some of my C++ objects. Your project is exactly what I need and I love the interface. Very good work!

My only problem is that it does not compile in VS2013. VS2010 does not support constexpr, so I did this:

#define constexpr const

Most of the errors go away, but I'm still stuck with those errors:

luaglueapplytuple.h(249): error C2061: syntax error : identifier 'uint'
luaglueapplytuple.h(262): error C2992: 'apply_func' : invalid or missing template parameter list
          luaglueapplytuple.h(251) : see declaration of 'apply_func'
luaglueapplytuple.h(285): error C2913: explicit specialization; 'apply_func' is not a specialization of a class template
luaglueapplytuple.h(315): error C2061: syntax error : identifier 'uint'
luaglueapplytuple.h(342): error C2977: 'apply_ctor_func' : too many template arguments
          luaglueapplytuple.h(317) : see declaration of 'apply_ctor_func'
luaglueapplytuple.h(349): error C2953: 'apply_ctor_func' : class template has already been defined
          luaglueapplytuple.h(317) : see declaration of 'apply_ctor_func'

Any help would be greatly appreciated !

JMLX42 commented 10 years ago

Doing this seams to get things to compile:

#define constexpr const
#define uint unsigned int
#include "LuaGlue/LuaGlue.h"
#undef constexpr
#undef uint

Then I do this in my code:

state
        .Class("Node")
            .method("getName", &scene::Node::name)
        .end()
        .open()
        .glue();

And I get a null pointer exception in LuaGlueMethod.h(81).

Here are the warnings I get at compile time:

luaglue\include\luaglue\luagluesymtab.h(165): warning C4018: '>' : signed/unsigned mismatch
luaglue\include\luaglue\luagluesymtab.h(164) : while compiling class template member function 'const LuaGlueSymTab::Symbol &LuaGlueSymTab::findSym(int)'
luaglue\include\luaglue\luagluesymtab.h(131) : see reference to function template instantiation 'const LuaGlueSymTab::Symbol &LuaGlueSymTab::findSym(int)' being compiled
luaglue\include\luaglue\luaglue.h(65) : see reference to class template instantiation 'LuaGlueSymTab' being compiled
luaglue\include\luaglue\luagluemethod.h(113): warning C4146: unary minus operator applied to unsigned type, result still unsigned
luaglue\include\luaglue\luagluemethod.h(104) : while compiling class template member function 'int LuaGlueMethod::invoke(lua_State *)'
          with
          [
              _Class=minko::scene::Node
          ]
luaglue\include\luaglue\luagluemethod.h(121) : see reference to function template instantiation 'int LuaGlueMethod::invoke(lua_State *)' being compiled
          with
          [
              _Class=minko::scene::Node
          ]
luaglue\include\luaglue\luaglueclass.h(163) : see reference to class template instantiation 'LuaGlueMethod' being compiled
          with
          [
              _Class=minko::scene::Node
          ]
          src\minko\file\luascriptparser.cpp(51) : see reference to function template instantiation 'LuaGlueClass &LuaGlueClass::method(const std::string &,void (__thiscall minko::scene::Node::* )(const std::string &))' being compiled
          src\minko\file\luascriptparser.cpp(54) : see reference to function template instantiation 'LuaGlueClass &LuaGlueClass::method(const std::string &,void (__thiscall minko::scene::Node::* )(const std::string &))' being compiled
c:\program files (x86)\microsoft visual studio 12.0\vc\include\tuple(74): warning C4413: 'std::_Tuple_val<_This>::_Val' : reference member is initialized to a temporary that doesn't persist after the constructor exits
          with
          [
              _This=const std::string &
          ]
          c:\program files (x86)\microsoft visual studio 12.0\vc\include\tuple(122) : see declaration of 'std::_Tuple_val<_This>::_Val'
          with
          [
              _This=const std::string &
          ]
          c:\program files (x86)\microsoft visual studio 12.0\vc\include\tuple(72) : while compiling class template member function 'std::_Tuple_val<_This>::_Tuple_val(void)'
          with
          [
              _This=const std::string &
          ]
          c:\program files (x86)\microsoft visual studio 12.0\vc\include\tuple(182) : see reference to function template instantiation 'std::_Tuple_val<_This>::_Tuple_val(void)' being compiled
          with
          [
              _This=const std::string &
          ]
          c:\program files (x86)\microsoft visual studio 12.0\vc\include\tuple(456) : see reference to class template instantiation 'std::_Tuple_val<_This>' being compiled
          with
          [
              _This=const std::string &
          ]
luaglue\include\luaglue\luagluemethod.h(99) : see reference to class template instantiation 'std::tuple' being compiled
luaglue\include\luaglue\luaglueapplytuple.h(194): warning C4146: unary minus operator applied to unsigned type, result still unsigned
luaglue\include\luaglue\luaglueapplytuple.h(233) : see reference to function template instantiation 'R apply_obj_func<1>::applyTuple(LuaGlue &,lua_State *,T *,R (__thiscall minko::scene::Node::* )(const std::string &),const std::tuple &)' being compiled
          with
          [
              R=void
  ,            T=minko::scene::Node
          ]
luaglue\include\luaglue\luaglueapplytuple.h(233) : see reference to function template instantiation 'R apply_obj_func<1>::applyTuple(LuaGlue &,lua_State *,T *,R (__thiscall minko::scene::Node::* )(const std::string &),const std::tuple &)' being compiled
          with
          [
              R=void
  ,            T=minko::scene::Node
          ]
luaglue\include\luaglue\luagluemethod.h(112) : see reference to function template instantiation 'R applyTuple<_Class,void,const std::string&,const std::string&>(LuaGlue &,lua_State *,T *,R (__thiscall minko::scene::Node::* )(const std::string &),const std::tuple &)' being compiled
          with
          [
              R=void
  ,            _Class=minko::scene::Node
  ,            T=minko::scene::Node
          ]
luaglue\include\luaglue\luagluemethod.h(104) : while compiling class template member function 'int LuaGlueMethod::invoke(lua_State *)'
          with
          [
              _Class=minko::scene::Node
          ]
luaglue\include\luaglue\luagluemethod.h(121) : see reference to function template instantiation 'int LuaGlueMethod::invoke(lua_State *)' being compiled
          with
          [
              _Class=minko::scene::Node
          ]
JMLX42 commented 10 years ago

Ok after fixing the signed/unsigned warnings, I'm left with:

2>c:\program files (x86)\microsoft visual studio 12.0\vc\include\tuple(74): warning C4413: 'std::_Tuple_val<_This>::_Val' : reference member is initialized to a temporary that doesn't persist after the constructor exits
2>          with
2>          [
2>              _This=const std::string &
2>          ]
2>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\tuple(122) : see declaration of 'std::_Tuple_val<_This>::_Val'
2>          with
2>          [
2>              _This=const std::string &
2>          ]
2>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\tuple(72) : while compiling class template member function 'std::_Tuple_val<_This>::_Tuple_val(void)'
2>          with
2>          [
2>              _This=const std::string &
2>          ]
2>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\tuple(182) : see reference to function template instantiation 'std::_Tuple_val<_This>::_Tuple_val(void)' being compiled
2>          with
2>          [
2>              _This=const std::string &
2>          ]
2>          c:\program files (x86)\microsoft visual studio 12.0\vc\include\tuple(456) : see reference to class template instantiation 'std::_Tuple_val<_This>' being compiled
2>          with
2>          [
2>              _This=const std::string &
2>          ]
2>          luaglue\luagluemethod.h(99) : see reference to class template instantiation 'std::tuple' being compiled
2>          luaglue\luaglueclass.h(163) : see reference to class template instantiation 'LuaGlueMethod' being compiled
2>          with
2>          [
2>              _Class=minko::scene::Node
2>          ]
2>          src\minko\file\luascriptparser.cpp(51) : see reference to function template instantiation 'LuaGlueClass &LuaGlueClass::method(const std::string &,void (__thiscall minko::scene::Node::* )(const std::string &))' being compiled
2>          src\minko\file\luascriptparser.cpp(54) : see reference to function template instantiation 'LuaGlueClass &LuaGlueClass::method(const std::string &,void (__thiscall minko::scene::Node::* )(const std::string &))' being compiled

So basically, I think that it doesn't like the fact you're returning *this here:

        template
        LuaGlueClass<_Class> &method(const std::string &name, void (_Class::*fn)(_Args...))
        {
            //printf("method(%s)\n", name.c_str());
            auto impl = new LuaGlueMethod(this, name, std::forward(fn));
            methods.addSymbol(name.c_str(), impl);

            return *this;
        }

Could you please explain how to fix this ?

Tomasu commented 10 years ago

Hi, thanks for reporting this, would you be able to provide a simple example of where this and the null pointer crash shows up?

LuaGlue depends very heavily on several C++11 features. VS hasn't been known to support the newest standards all that quickly. I will do what I can to try and work around any VS specific issues, but I can't guarantee anything.

JMLX42 commented 10 years ago

Here is my code:

namespace minko
{
    namespace scene
    {
        class Node :
            public std::enable_shared_from_this
        {
        public:
            typedef std::shared_ptr   Ptr;
        protected:
            std::string     _name;
                public:
            inline
            const std::string&
            name()
            {
                return _name;
            }
            inline
            void
            name(const std::string& name)
            {
                _name = name;
            }
                }
        }
}
    static LuaGlue state;
    state
        .Class("Node")
              .method("setName", &scene::Node::name)
        .end()
        .open()
        .glue();

I agree scene::Node::name is not explicit. It's not the issue though...

If you are interested in helping us integrating LuaGlue with our open source C++11 cross-platform 3D engine I could give you access to our alpha version in our repo (it's not public yet).

Regards,

Tomasu commented 10 years ago

Hm, I do see a similar error with code like that. It seems it's not liking trying to set up the "const std::string &" aka a const string reference. I'll need to spend some more time on that soon.

JMLX42 commented 10 years ago

I updated the code with your latest changes and I added more binding stuff on my side. The warnings are still here, and I got a few errors too:

1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(137): error C2645: no qualified name for pointer to member (found ':: *')
1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(137): error C2062: type 'void' unexpected
1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(147): error C2825: '_Class': must be a class or namespace when followed by '::'
1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(147): error C2645: no qualified name for pointer to member (found ':: *')
1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(147): error C2275: '_Class' : illegal use of this type as an expression
1>          lib\LuaGlue\include\LuaGlue/LuaGlueApplyTuple.h(158) : see declaration of '_Class'
1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(147): error C2143: syntax error : missing ')' before '`global namespace''
1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(147): error C2059: syntax error : ')'
1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(157): error C2825: '_Class': must be a class or namespace when followed by '::'
1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(157): error C2645: no qualified name for pointer to member (found ':: *')
1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(158): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(167): error C2825: '_Class': must be a class or namespace when followed by '::'
1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(167): error C2645: no qualified name for pointer to member (found ':: *')
1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(167): error C2143: syntax error : missing ',' before '`global namespace''
1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(180): error C2825: '_Class': must be a class or namespace when followed by '::'
1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(180): error C2645: no qualified name for pointer to member (found ':: *')
1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(180): error C2143: syntax error : missing ',' before '`global namespace''
1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(190): error C2825: '_Class': must be a class or namespace when followed by '::'
1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(190): error C2645: no qualified name for pointer to member (found ':: *')
1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(190): error C2751: '`global namespace'' : the name of a function parameter cannot be qualified
1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(190): error C2146: syntax error : missing ',' before identifier 'fn'
1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(190): error C2091: function returns function
1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(200): error C2825: '_Class': must be a class or namespace when followed by '::'
1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(200): error C2645: no qualified name for pointer to member (found ':: *')
1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(200): error C2751: '`global namespace'' : the name of a function parameter cannot be qualified
1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(200): error C2146: syntax error : missing ',' before identifier 'fn'
1>lib\LuaGlue\include\LuaGlue/LuaGlueClass.h(200): error C2091: function returns function
1>          lib\LuaGlue\include\LuaGlue/LuaGlueApplyTuple.h(158) : see declaration of '_Class'
1>          lib\LuaGlue\include\LuaGlue/LuaGlueApplyTuple.h(158) : see declaration of '_Class'

Here is my code:

    state
        .Class("Vector2")
            .method("setX", static_cast(&math::Vector2::x))
            .method("setX", static_cast(&math::Vector2::x))
            .method("setY", static_cast(&math::Vector2::y))
            .method("setY", static_cast(&math::Vector2::y))
        .end()
        .Class("Vector3")
            .method("setX", static_cast(&math::Vector3::x))
            .method("setX", static_cast(&math::Vector3::x))
            .method("setY", static_cast(&math::Vector3::y))
            .method("setY", static_cast(&math::Vector3::y))
            .method("setZ", static_cast(&math::Vector3::z))
            .method("setZ", static_cast(&math::Vector3::z))
        .end()
        .Class("Vector4")
            .method("setX", static_cast(&math::Vector4::x))
            .method("setX", static_cast(&math::Vector4::x))
            .method("setY", static_cast(&math::Vector4::y))
            .method("setY", static_cast(&math::Vector4::y))
            .method("setZ", static_cast(&math::Vector4::z))
            .method("setZ", static_cast(&math::Vector4::z))
            .method("setW", static_cast(&math::Vector4::w))
            .method("setW", static_cast(&math::Vector4::w))
        .end()
        .Class("Matrix4x4")
            .method("appendRotationX",      &math::Matrix4x4::appendRotationX)
            .method("appendRotationY",      &math::Matrix4x4::appendRotationY)
            .method("appendRotationZ",      &math::Matrix4x4::appendRotationZ)
            .method("appendRotation",       &math::Matrix4x4::appendRotation)
            .method("appendTranslation",    static_cast(&math::Matrix4x4::appendTranslation))
            .method("appendTranslation",    static_cast(&math::Matrix4x4::appendTranslation))
            .method("prependRotationX",     &math::Matrix4x4::prependRotationX)
            .method("prependRotationY",     &math::Matrix4x4::prependRotationY)
            .method("prependRotationZ",     &math::Matrix4x4::prependRotationZ)
            .method("prependRotation",      &math::Matrix4x4::prependRotation)
            .method("prependTranslation",   static_cast(&math::Matrix4x4::prependTranslation))
            .method("prependTranslation",   static_cast(&math::Matrix4x4::prependTranslation))
        .end()
        .Class("Container")
            .method("getFloat",     &data::Container::get)
            .method("getInt",       &data::Container::get)
            .method("getUint",      &data::Container::get)
            .method("getMatrix4x4", &data::Container::get)
        .end()
        .Class("Node")
            .method("getName",          static_cast(&scene::Node::name))
            .method("setName",          static_cast(&scene::Node::name))
            .method("getData",          &scene::Node::data)
            .method("addChild",         &scene::Node::addChild)
            .method("removeChild",      &scene::Node::removeChild)
            .method("contains",         &scene::Node::contains)
            .method("addComponent",     &scene::Node::addComponent)
            .method("removeComponent",  &scene::Node::removeComponent)
        .end()
        .open()
        .glue();

I'll make a pull request for the VS2013 compatibility issues I already solved.

Thanks again for you help!

JMLX42 commented 10 years ago

All VS2013 related issues should be fixed by this pull request: https://github.com/Tomasu/LuaGlue/pull/9 The remaining errors are now tracked in the #10 issue.