Re: Error trying to export class

Ali Hajiabadi <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
Hi,
I'm not sure about your first question, I think you should use something
like this :
MyPoint = point2d()

but about your second question I use this :

    luaL_dostring(LuaState,"func(2,3)");
    if (lua_isstring(LuaState, lua_gettop(LuaState))) {
        std::cout << lua_tostring(LuaState,lua_gettop(LuaState)) << "\n";
        lua_pop(LuaState, 1);
    }

----------------------------

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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.