lua-users home
lua-l archive

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


You'll want to look at SWIG_TypeQuery and SWIG_NewPointerObj(). You should have SWIG generate a header for you to include in your code, which is where SWIG_TypeQuery and SWIG_NewPointerObj will be defined. You can get that by running "swig -lua -external-runtime -o SwigRuntime.h". Include SwigRuntime.h in any code you have that needs to interact with the Swig-generated code.

To expose objects from C++, I've usually had a method doing the following:

bool LuaPushObject( const char* typeName, void* obj, bool own )
{   
    swig_type_info* typeinfo = SWIG_TypeQuery( m_L, typeName );
    if ( typeinfo != NULL )
    {   
        SWIG_NewPointerObj( m_L, obj, typeinfo, (own ? 1 : 0) );
        return true;
    }   
    return false;
}

I hope that helps...

-Michael Wyman


On Apr 14, 2011, at 3:37 PM, Lucas Zawacki wrote:

> Hello all. I've recently used SWIG to successfully bind a lot of C++
> classes to be used from inside some lua scripts. However I want to be
> able to create some of these objects in the C++ side and then expose
> them to the Lua scripts and that's proving to be quite hard.
> 
> The SWIG function "_wrap_new_Class()" seems to create a new object of
> type Class and leave it on top of the stack so it looks like the way
> to go, but I'm getting an undefined reference to it. I tried to issue
> a prototype like "extern _wrap_new_Class(lua_State* L);" in the file
> using it but it doesn't seem to have any effect.
> 
> The compile line I'm using is more or like "g++ main.cpp
> file_using_cpp_obj.o all_the_bound_classes.a -llua -ldl".
> 
> Thanks for your time
>