Registering Pre Allocated Elements
Last changed: -92.222.238.172

.

Back to SqPlus

Summary

C/C++ binding:


// Example from forum post question:
class STestScripts {}; // Proxy class
class TestScripts {
public:
  int Var_ToBind1,Var_ToBind2;

  void InitScript1(void) {
    Var_ToBind1 = 808;
    RegisterGlobal(*this,Test1,"Test1");
    RegisterGlobal(*this,Test2,"Test2");
    BindVariable(&Var_ToBind1,"Var_ToBind1");
  } // InitScript1

  void InitScript2(void) {
    Var_ToBind2 = 909;
    SQClassDef<STestScripts>("STestScripts").
      staticFunc(*this,Test1,"Test1").
      staticFunc(*this,Test2,"Test2").
      staticVar(&Var_ToBind2,"Var_ToBind2");
  } // InitScript2

  void Test1(void) {
    printf("Test1 called.\n");
  }
  void Test2(void) {
    printf("Test2 called.\n");
  }
} testScripts;

Script test:

testScripts.InitScript1();
testScripts.InitScript2();
SquirrelObject testScriptBinding = SquirrelVM::CompileBuffer("\
  local testScripts = STestScripts(); \n\
  testScripts.Test1(); \n\
  testScripts.Test2(); \n\
  print(testScripts.Var_ToBind2); \n\
  Test1(); \n\
  Test2(); \n\
  print(Var_ToBind1); \n\
");
SquirrelVM::RunScript(testScriptBinding);