|
View:
New views
11 Messages
—
Rating Filter:
Alert me
|
|
|
How to bind C++ method with lua function as parameter?hi,
here's the short form of the classes I'm trying to use from lua: struct Event { std::string type; }; struct EventDispatcher { // used to register lua event handlers void addEventListener(const std::string& inEventType, luabind::object inFunc); // used to register c++ event handlers, not visible to lua void addEventListener(const std::string& inEventType, boost::function<void(boost::shared_ptr<Event>)> inFunc); }; I want to be able to dispatch Events from lua and C++, and also register handlers in both languages. Unfortunately, I can bind the class and everything compiles ok, but when I try to use it, I get a luabind runtime error: function genericHandler(ev) print(ev.type) end eventDispatcher.addEventListener("hello", genericHandler) gives me a luabind error about mismatched signatures: string, function, possible candidates are const string&, object. What is going on here? I thought lua functions were just ordinary luabind::objects? hope you can help, best regards, Tony __________________________________________________________ Gesendet von Yahoo! Mail. Dem pfiffigeren Posteingang. http://de.overview.mail.yahoo.com ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ luabind-user mailing list luabind-user@... https://lists.sourceforge.net/lists/listinfo/luabind-user |
|
|
Re: How to bind C++ method with lua function as parameter?It helps if you give us the full source code to your program, and how
you compile it. What version of lua and luabind are you using (ie luabind 0.7 and lua 5.0, or luabind svn and lua5.1?) And what is the error message? Not a paraphrase, but the actual message lua gave you? Did you compile luabind yourself, and what version are your boost headers? Without details, we can only speculate on what your problem might be. ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ luabind-user mailing list luabind-user@... https://lists.sourceforge.net/lists/listinfo/luabind-user |
|
|
Re: How to bind C++ method with lua function as parameter?hi Brandon,
thanks for the reply! I'm on Mac OS X 10.5.3, XCode 3.1, gcc 4.0, lua 5.1.3, luabind 0.7 (the download from sourceforge, NOT the svn), boost 1.34.1. I'm building lua and luabind myself as static libraries in XCode projects where I just dropped in all the implementation files. In order to get luabind 0.7 to compile with lua 5.1.3 I had to add the following two defines to luabind/lua_include.hpp : #define LUA_NOREF (-2) #define LUA_REFNIL (-1) Apart from that, not modifications or configurations were performed by me, neither in lua nor luabind. The following sourcecode is a complete example main.cpp that will reproduce the error. The exact luabind runtime error is: no overload of 'EventDispatcher:addEventListener' matched the arguments (string, function) candidates are: EventDispatcher:addEventListener(const string&, object) I really hope you can help! Thanks a lot, Tony #include <iostream> #include <string> #include <boost/shared_ptr.hpp> #include <list> #include <stdexcept> #include <boost/function.hpp> #include <map> #include <iostream> extern "C" { #include "lua.h" #include "lauxlib.h" #include "lualib.h" } #include <luabind/luabind.hpp> struct Event { Event(const std::string& inType) : type(inType) {} virtual ~Event() {} std::string type; }; struct EventQueue { std::size_t size() { return eventqueue.size(); } void push(boost::shared_ptr<Event> event) {eventqueue.push_back(event); } boost::shared_ptr<Event> pop() { if(size() > 0) { boost::shared_ptr<Event> result = eventqueue.front(); eventqueue.pop_front(); return result; } else throw std::runtime_error("called pop on empty queue"); } private: std::list<boost::shared_ptr<Event> > eventqueue; }; struct EventDispatcher { typedef boost::shared_ptr<Event> EventPtr; typedef boost::function<void(EventPtr)> HandlerFuncType; typedef std::map<std::string, HandlerFuncType > HandlerMap; struct LuaHandlerFunc { luabind::object handler; LuaHandlerFunc(luabind::object inHandler) : handler(inHandler) {} void operator()(EventPtr event) { luabind::call_function<void>(handler, event); } }; EventDispatcher() { } virtual ~EventDispatcher() { } void dispatchEvent(boost::shared_ptr<Event> event) { eventQueue.push(event); } void addEventListener(const std::string& inEventType, HandlerFuncType handlerFunc) { type2handler[inEventType] = handlerFunc; } void addEventListener(const std::string& inEventType, const luabind::object& handler) { std::cout << "adding lua listener" << std::endl; type2handler[inEventType] = LuaHandlerFunc(handler); } void doDispatch() { while(eventQueue.size() > 0) { EventPtr event = eventQueue.pop(); HandlerMap::iterator pos = type2handler.find(event->type); if(pos != type2handler.end()) { pos->second(event); } else { std::cout << "discarding event of type: " << event->type << std::endl; } } } private: HandlerMap type2handler; EventQueue eventQueue; }; using namespace std; using namespace luabind; namespace luabind { template<class Event> Event* get_pointer(boost::shared_ptr<Event>& p) { return p.get(); } template<class Event> boost::shared_ptr<const Event>* get_const_holder(boost::shared_ptr<Event>*) { return 0; } } void bindClasses(lua_State* state) { module(state) [ class_<Event, boost::shared_ptr<Event> >("Event") .def(constructor<string>()) .def_readwrite("type", &Event::type), class_<EventDispatcher>("EventDispatcher") .def(constructor<>()) .def("dispatchEvent", &EventDispatcher::dispatchEvent) .def("addEventListener", (void(EventDispatcher::*)(const std::string&, const luabind::object&)) &EventDispatcher::addEventListener) .def("doDispatch", &EventDispatcher::doDispatch) ]; } string luaprog = "function genericHandler(ev)\n" " print('Lua got event: '..(ev.type))\n" "end\n" "eventDispatcher = EventDispatcher()\n" "eventDispatcher.addEventListener('hello', genericHandler)\n" "eventDispatcher.dispatchEvent(Event('hello'))\n" "eventDispatcher.doDispatch()\n"; int main() { lua_State* state = lua_open(); luaL_openlibs(state); open(state); bindClasses(state); if(luaL_dostring(state, luaprog.c_str())) { std::string errstring = lua_tostring(state, -1); lua_pop(state,1); cout << errstring << endl; } lua_close(state); } Am 17.06.2008 um 14:20 schrieb Brandon: > It helps if you give us the full source code to your program, and how > you compile it. What version of lua and luabind are you using (ie > luabind 0.7 and lua 5.0, or luabind svn and lua5.1?) And what is the > error message? Not a paraphrase, but the actual message lua gave you? > Did you compile luabind yourself, and what version are your boost > headers? Without details, we can only speculate on what your problem > might be. > > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://sourceforge.net/services/buy/index.php > _______________________________________________ > luabind-user mailing list > luabind-user@... > https://lists.sourceforge.net/lists/listinfo/luabind-user ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ luabind-user mailing list luabind-user@... https://lists.sourceforge.net/lists/listinfo/luabind-user |
|
|
Re: How to bind C++ method with lua function as parameter?Thanks for the additional info. I tried compiling your code using
lua5.1, luabind 0.7 and boost 1.34.1 (Debian Testing repo versions). Your code didn't compile, with or without the changes you made to luabind/lua_include.hpp. Here is the beginning of the error message I got: /usr/include/luabind/class.hpp: In static member function 'static void luabind::detail::convert_holder<HeldType, ConstHolderType>::apply(void*, void*) [with HeldType = ConstHolderType>boost::shared_ptr<Event>, ConstHolderType = ConstHolderType>luabind::detail::you_need_to_define_a_get_const_holder_function_for_your_smart_ptr]': / I tried "fixing" the problem by changing line 134 to read: class_<Event>("Event") This would let the program compile, but would then segfault on open(state). To be honest, I'm a luabind newbie. You might know more than I do. Hopefully someone else will come along and be able to help you. -Brandon ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ luabind-user mailing list luabind-user@... https://lists.sourceforge.net/lists/listinfo/luabind-user |
|
|
Re: How to bind C++ method with lua function as parameter?I haven't looked at your code much but the engine I am developing I think is doing the exact same thing you are trying to do (event dispatching into lua?). Metaphor Game Engine is a component based game engine where components can be implemented in pure lua. I am very pleased with how the messaging system turned out.
Here are some direct links to the code where, even if you choose not to rip my code as-is, you might be able to figure out what is different between yours and mine and in doing so fix yours. Messaging.h Messaging.cpp These are tests that somewhat demonstrate what the event system looks like from a user perspective C++ Event Binding Lua Event Binding YMMV - let me know if you have any questions about the code I linked or the engine in general. If you see anything in my code that could be improved with an approach you have taken, I would very much appreciate your input. Philip On Tue, Jun 17, 2008 at 5:47 PM, Brandon <winterknight@...> wrote: Thanks for the additional info. I tried compiling your code using ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ luabind-user mailing list luabind-user@... https://lists.sourceforge.net/lists/listinfo/luabind-user |
|
|
Re: How to bind C++ method with lua function as parameter?This may be more relevant - in my lua event binding test example, you see that I am calling the function registerHandler, passing in 3 parameters: a String, the lua object to call the function on, and the function itself. Here is the C++ prototype for the function that it is bound to:
void LuaComponent::registerHandler(std::string messageName, luabind::object obj, luabind::object function)Here is my lua binding code for the class that has that function: luabind::class_<LuaComponent, LuaComponentWrapper, Objects::Component>("LuaComponent")Philip
On Tue, Jun 17, 2008 at 8:20 PM, Philip Degarmo <aclysma@...> wrote: I haven't looked at your code much but the engine I am developing I think is doing the exact same thing you are trying to do (event dispatching into lua?). Metaphor Game Engine is a component based game engine where components can be implemented in pure lua. I am very pleased with how the messaging system turned out. ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ luabind-user mailing list luabind-user@... https://lists.sourceforge.net/lists/listinfo/luabind-user |
|
|
boost language bindingHi,
i wonder some time now, why is the boost language binding initiative dead. As far as i know it was introduced by boost::python and luabind developers. So why is it dead? -chris ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ luabind-user mailing list luabind-user@... https://lists.sourceforge.net/lists/listinfo/luabind-user |
|
|
Re: boost language bindingBecause nobody has stepped up to actually design and implement it.
FWIW, there a many people interested in it, including several entities that will fund its development. So, if somebody has the skillz, step up to the plate :) -Evan Christopher Lux wrote: > Hi, > i wonder some time now, why is the boost language binding initiative > dead. As far as i know it was introduced by boost::python and luabind > developers. So why is it dead? > > -chris > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://sourceforge.net/services/buy/index.php ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ luabind-user mailing list luabind-user@... https://lists.sourceforge.net/lists/listinfo/luabind-user |
|
|
Re: boost language bindingChristopher Lux wrote:
> Hi, > i wonder some time now, why is the boost language binding initiative > dead. As far as i know it was introduced by boost::python and luabind > developers. So why is it dead? We lack the necessary funding to work on it. There is some effort going on to raise funds for the project, but no results yet. -- Daniel Wallin BoostPro Computing http://www.boostpro.com ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ luabind-user mailing list luabind-user@... https://lists.sourceforge.net/lists/listinfo/luabind-user |
|
|
Re: boost language bindingEvan Wies wrote:
> Because nobody has stepped up to actually design and implement it. > > FWIW, there a many people interested in it, including several entities that will fund its development. > > So, if somebody has the skillz, step up to the plate :) IIRC, nothing concrete ever came of the funding, am I missing something? I would be more than happy to start working on it, provided the funding was in place. -- Daniel Wallin BoostPro Computing http://www.boostpro.com ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ luabind-user mailing list luabind-user@... https://lists.sourceforge.net/lists/listinfo/luabind-user |
|
|
Re: [SOLVED] How to bind C++ method with lua function as parameter?hey guys,
thanks for all the feedback! Luckily, Mr Neomantra on #luabind pointed out to me that I was trying to call methods with the dot operator instead of the colon, which resulted in the confusing error message. Talk about noobness :) Brandon, it's weird that the code failed to compile, but my shared_ptr getters might not be correct after all, because I stumbled over another problem with them today ... will have to investigate. Philip, you've got an interesting project going on there, and I like the looks of your site and the code. I'll try and check it out in a few weeks, when I have some time left. thanks again, best, Tony Am 18.06.2008 um 03:44 schrieb Philip Degarmo: > This may be more relevant - in my lua event binding test example, > you see that I am calling the function registerHandler, passing in 3 > parameters: a String, the lua object to call the function on, and > the function itself. Here is the C++ prototype for the function that > it is bound to: > void LuaComponent::registerHandler(std::string messageName, > luabind::object obj, luabind::object function) > { > getOwner()->registerMessageHandler(messageName, obj, function); > > } > Here is my lua binding code for the class that has that function: > luabind::class_<LuaComponent, LuaComponentWrapper, > Objects::Component>("LuaComponent") > > .def(luabind::constructor<>()) > .def("initialize", &LuaComponent::initialize, > &LuaComponentWrapper::default_initialize) > ...other stuff... > .def("registerHandler", &LuaComponent::registerHandler) > > > Your code makes sense to me, but honestly, the non-trivial things I > have to bind are generally done with a trial-and-error approach > because I really don't know much beyond the very basics. > Philip > > On Tue, Jun 17, 2008 at 8:20 PM, Philip Degarmo <aclysma@...> > wrote: > I haven't looked at your code much but the engine I am developing I > think is doing the exact same thing you are trying to do (event > dispatching into lua?). Metaphor Game Engine is a component based > game engine where components can be implemented in pure lua. I am > very pleased with how the messaging system turned out. > > Here are some direct links to the code where, even if you choose not > to rip my code as-is, you might be able to figure out what is > different between yours and mine and in doing so fix yours. > Messaging.h > Messaging.cpp > > These are tests that somewhat demonstrate what the event system > looks like from a user perspective > C++ Event Binding > Lua Event Binding > > YMMV - let me know if you have any questions about the code I linked > or the engine in general. If you see anything in my code that could > be improved with an approach you have taken, I would very much > appreciate your input. > > Philip > > > On Tue, Jun 17, 2008 at 5:47 PM, Brandon > <winterknight@...> wrote: > Thanks for the additional info. I tried compiling your code using > lua5.1, luabind 0.7 and boost 1.34.1 (Debian Testing repo versions). > Your code didn't compile, with or without the changes you made to > luabind/lua_include.hpp. Here is the beginning of the error message I > got: > > /usr/include/luabind/class.hpp: In static member function 'static void > luabind::detail::convert_holder<HeldType, > ConstHolderType>::apply(void*, void*) [with HeldType = > ConstHolderType>boost::shared_ptr<Event>, ConstHolderType = > ConstHolderType > > > luabind > ::detail > ::you_need_to_define_a_get_const_holder_function_for_your_smart_ptr > ]': / > > I tried "fixing" the problem by changing line 134 to read: > class_<Event>("Event") > This would let the program compile, but would then segfault on > open(state). > > To be honest, I'm a luabind newbie. You might know more than I do. > Hopefully someone else will come along and be able to help you. > > -Brandon > > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://sourceforge.net/services/buy/index.php > _______________________________________________ > luabind-user mailing list > luabind-user@... > https://lists.sourceforge.net/lists/listinfo/luabind-user > > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://sourceforge.net/services/buy/index.php_______________________________________________ > luabind-user mailing list > luabind-user@... > https://lists.sourceforge.net/lists/listinfo/luabind-user ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ luabind-user mailing list luabind-user@... https://lists.sourceforge.net/lists/listinfo/luabind-user |
| Free Forum Powered by Nabble | Forum Help |