A simple/minimal example was missing from SqPlus: simple examples shown below.
(Updated versions with the example code and additional info here:
http://wiki.squirrel-lang.org/default.aspx/SquirrelWiki/SqPlus.html.
The code should compile and link with no warnings or errors with VS.NET 2003 (should also work with VS8 beta2). If a GNUMakefile is created for GCC, let me know if there are any issues with GCC builds and I'll fix them).
Minimal Hello World example:
#include "sqplus.h"
using namespace SqPlus;
int main(int argc,char * argv[]) {
SquirrelVM::Init();
SquirrelObject helloWorld = SquirrelVM::CompileBuffer("print(\"Hello World\");");
SquirrelVM::RunScript(helloWorld);
SquirrelVM::Shutdown();
return 0;
} // main
Minimal example with class binding:
#include <stdio.h>
#include "sqplus.h"
using namespace SqPlus;
class MyClass {
public:
int classVal;
// See examples in testSqPlus2.cpp for passing arguments to the constructor (including variable arguments).
MyClass() : classVal(123) {}
bool process(int iVal,const char * sVal) {
printf("classVal: %d, iVal: %d, sVal %s\n",classVal,iVal,sVal);
classVal += iVal;
return iVal > 1;
} // process
};
int main(int argc,char * argv[]) {
SquirrelVM::Init();
SQClassDef<MyClass>("MyClass").
func(MyClass::process,"process").
var(&MyClass::classVal,"classVal");
// Line continuations removed from this post to simplify formating.
SquirrelObject helloSqPlus = SquirrelVM::CompileBuffer("
local myClass = MyClass();
local rVal = myClass.process(1,\"MyClass1\");
print(\"Returned: \"+(rVal ? \"true\" : \"false\"));
rVal = myClass.process(2,\"MyClass2\");
print(\"Returned: \"+(rVal ? \"true\" : \"false\"));
print(\"classVal: \"+myClass.classVal);
");
SquirrelVM::RunScript(helloSqPlus);
SquirrelVM::Shutdown();
return 0;
} // main
This version also provides
easy bindings for class/struct instance variables.
See the SqPlus Wiki (link above) for more examples (including example code for using the remote debugger, more class binding examples including constants, static functions and variables, variable number of arguments, custom constructors and destructors, calling Squirrel functions from C/C++, passing class instances to/from Squirrel, etc.).
[Edited by - John Schultz on October 21, 2005 1:31:04 PM]