Re: Error trying to export class
Ferran Ferri <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
I'm programming in Visual C++ 2008 and luabind 0.9.1. System is Win7 64bits.
The part that is annoying me is that this works fine:
luabind::module(L)
[
luabind::class_<testclass>("testclass")
.def(luabind::constructor<const std::string&>())
.def("print_string", &testclass::print_string)
];
And script:
function func(first, second)
a = testclass('a string')
a:print_string()
return 0
end
In addition I can say that program fails after the constructor is callled.
In script, this line works ok:
MyPoint = Point2D()
(and even MyPoint = Point2D )
But
MyPoint:setXY(3,4)
and
MyPoint:printXY()
fails, enven independently called.
Thanks
Ferran
On Fri, Dec 31, 2010 at 6:53 PM, Tony Kostanjsek <[email protected]>wrote:
> sorry, just saw those were the 2 + 3 params from the C++ call. If it isn't
> the constructor call, maybe you are using DLLs and the build is broken. Post
> some more details, OS, compiler, how you build.
>
> ------------------------------
> *Von:* Ferran Ferri <[email protected]>
> *An:* [email protected]
> *Gesendet:* Freitag, den 31. Dezember 2010, 17:48:17 Uhr
> *Betreff:* [luabind] Error trying to export class
>
> Hello all, I have a question. I'm a newbie: First, this is my c++ code
> #include <iostream>
> #include <cstdlib>
>
> extern "C" {
> #include "lua.h"
> #include "lualib.h"
> #include "lauxlib.h"
> }
>
> #include "luabind/luabind.hpp"
>
> using namespace std;
>
> class Point2D{
> int _x,_y;
> public:
> Point2D():_x(0),_y(0){}
> void setXYPoint(int x, int y){_x = x; _y = y;}
> void printPoint(){std::cout << "X = "<<_x<<" Y = "<<_y<<"\n";}
> void publishAPI(const lua_State* L){}
> };
>
>
> int main(){
>
> lua_State *L = lua_open();
>
> // Connect LuaBind to this lua state
> luabind::open(L);
> luaL_openlibs(L);
> luabind::module(L)[
> luabind::class_<Point2D>("point2d")
> .def(luabind::constructor<>())
> .def("print",&Point2D::printPoint)
> .def("setXY",&Point2D::setXYPoint)
> ];
>
> // Define a lua function that we can call
> luaL_dofile(L,"main.lua");
> try{
> std::cout << "Result: "
> << luabind::call_function<int>(L, "func", 2, 3)
> << endl;
> lua_close(L);
> }
> catch(const std::exception& e){
> std::cout << e.what() << std::endl;
> }
> return EXIT_SUCCESS;
>
> }
>
> And this is my lua script
>
> function func(first, second)
> MyPoint = point2d
> MyPoint:setXY(3,4)
> MyPoint:print()
> return first + second
> end
>
> The only result I always get is "lua runtime exception". But the program
> compiles fine and it seems legal. Could you help me please? This is very
> similar to others samples.
>
> Another question is: how do I get a more detailed error message? I always
> get "lua runtime exception" and I need a more comprehensive error
>
> Thanks in advance.
> Ferran
>
>
>
>
> ------------------------------------------------------------------------------
> Learn how Oracle Real Application Clusters (RAC) One Node allows customers
> to consolidate database storage, standardize their database environment,
> and,
> should the need arise, upgrade to a full multi-node Oracle RAC database
> without downtime or disruption
> http://p.sf.net/sfu/oracle-sfdevnl
> _______________________________________________
> luabind-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
>
------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user