lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

I am trying to use lunar.h from http://lua-users.org/wiki/CppBindingWithLunar , but i am not able to call it from my lua code.

Here is the scenario

I have a cpp class Parser which is derived from BaseModule. BaseModule has two functions with signature
    int set_mapping(lua_State *L)  and     int get_mapping(lua_State *L)
I am creating the Parser object in cpp and want to let my script call these two methods from script

so i used the following code in my constructor

    Lunar<Parser>::Register(script_land.L);
    int parser_instance = Lunar<Parser>::push(script_land.L,this);
    lua_pushliteral(script_land.L,"reader");
    lua_pushvalue(script_land.L,parser_instance);
    lua_settable(script_land.L,LUA_GLOBALSINDEX);

Also i have

const char Parser::className[] = "Parser";

#define method(class, name) {#name, &class::name}

Lunar<Parser>::RegType Parser::methods[] = {
  method(Parser, get_mapping),
  method(Parser, set_mapping),
  {0,0}
};


but when i try to print(reader:get_mapping) i get and error : attempt to call a nil value

How can i possibly debug this ? I also have a constructor function of the signature Parser(lua_State *L) but that does nothing. Can this be the problem

I have also tried this
a = reader:new()
print (a)

this gives me a output something like this

Parser (0xbfa2c498)



Please help me.


-Abhinav

--
Robert Benchley  - "Drawing on my fine command of the English language, I said nothing."