c++squirrel

How to register a Squirrel class in C++


Hello I'm trying to make use of Squirrel within a C++ application. For this reason I want to register a Squirrel class in C++.
Let's take the following class as an example.

class Foo
{
    constructor(value)
    {
        ::print("constructor called");
        this.testValue = value;
    }

    function saySomething()
    {
        ::print("The value is: " + this.testValue);
    }

    testValue = 0;
}

Can anybody please show me how to bind it in C++?


Solution

  • I was able to do it, by using this code.

    In my example it would look like this:

    sqext::SQIClass testClass(L"Foo");
    testClass.bind(0, L"testValue");
    testClass.bind(1, L"saySomething");
    
    sqext::SQIClassInstance test = testClass.New(4711);
    test.call(1);