如何在C++注册松鼠类

How to register a Squirrel class in C++

本文关键字:注册 C++      更新时间:2023-10-16

您好,我正在尝试在C++应用程序中使用Squirrel。出于这个原因,我想在C++注册一个松鼠类。
让我们以下面的类为例。

class Foo
{
    constructor(value)
    {
        ::print("constructor called");
        this.testValue = value;
    }
    function saySomething()
    {
        ::print("The value is: " + this.testValue);
    }
    testValue = 0;
}

任何人都可以告诉我如何在C++中绑定它吗?

我能够做到这一点,通过使用这段代码。

在我的示例中,它看起来像这样:

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