OK i'm getting closer to solving this problem.
I took a look at python and saw they are using a wrapper class. So i did the same with squirrel.
Now i can pass a class made in squirrel back to c++ and the functions are called.
Note: i made the wrapper a template bc boost.python is doing it too. dunno why maybe i will remove it when i find out it doesn't do anything i would need(still ready boost code).
One thing is there a way i could check if the function is declared in the squirel object? bc like this i can only wrap pure virtual function none with standard implementations. oh and another thing am i recreating the function everytime i call it? maybe there is a more ellegant way of doing this.
C++:
//class to export to squirrel
class FOO
{
public:
virtual void do(void) = 0;
};
//the wrapper
template<typename T>
class wrapper
{
public:
wrapper(void)
{
AppFrame::ILogger::log("creating wrapper");
}
virtual ~wrapper(void)
{
}
void setObject(SquirrelObject obj)
{
m_obj = obj;
}
template<typename R>
SquirrelFunction<R>& getFunction(const char* name)
{
SquirrelFunction<R> f(m_obj, name);
AppFrame::ILogger::log("created fuction without");
return f;
}
private:
SquirrelObject m_obj;
};
//make a squirrel imp for exporting
class SQFOO : public FOO, public wrapper<FOO>
{
public:
virtual void do(void)
{
getFunction<void>("do")();
}
};
//now export
DECLARE_INSTANCE_TYPE(FOO)
DECLARE_INSTANCE_TYPE(SQFOO)
//this is the important part where u bind the squirrel object to c++ one so u can really use vars from the squirrel object
int FooConstructor(HSQUIRRELVM v)
{
SQFOO* f = new SQFOO();
int r = PostConstruct<SQFOO>(v, state, ReleaseClassPtr<SQFOO>::release);
StackHandler sa(v);
HSQOBJECT ho = sa.GetObjectHandle(1); // OT_INSTANCE
SquirrelObject instance(ho);
state->setObject(instance);
return r;
}
//bind the constructor
void bind_IGameState(void)
{
SQClassDef<SQFOO>(_T("FOO")).
staticFunc(FooConstructor,_T("constructor"));
}
SQUIRREL:
class MyFoo extends FOO
{
function do
{
print("here i am");
}
}