Search

Search:

Use Regular Expressions for search

Namespace:

Search Result
.
  SquirrelObject test = SquirrelVM::CompileBuffer("\
.
  SquirrelObject test2 = SquirrelVM::CompileBuffer("\
.
  SquirrelObject inst = SquirrelVM::CompileBuffer("\
.

SquirrelObject testScriptBinding = SquirrelVM::CompileBuffer("\

.
        typedef std::vector<SquirrelObject> ObjectList;
.
                SquirrelObject item;
.
        SquirrelObject dobj(&d);
.
        SquirrelObject root = SquirrelVM::GetRootTable();
.
       SquirrelObject testStaticVars = SquirrelVM::CompileBuffer(_T(" local v = Vector3(); local v2 = Vector3(); local v3 = v+v2; v3 += v2; print(\"v3.x: \"+v3.x); print(\"Vector3::staticVar: \"+v.staticVar+\" Vector3::globalVar: \"+v.globalVar); v.staticVar = 0; "));
.
       SquirrelObject testRegV = SquirrelVM::CompileBuffer(_T(" local vec = Vector3(); print(vec.x); vec = vec.Add(vec); print(vec.x); vec = vec.Add(vec); print(vec.x); vec = vec.Add2(vec,vec); print(vec.x); local v2 = Vector3(); vec = v2.Inc(vec); print(vec.x); print(v2.x); "));
.

+ SquirrelObject testOverload = SquirrelVM::CompileBuffer(

.
       SquirrelObject testReg0 = SquirrelVM::CompileBuffer(_T(" co <- CustomTestObj(\"hello\",123,true); co.varArgTypes(\"str\",123,123,\"str\"); co.varArgTypes(123,\"str\",\"str\",123); "));
.
            SquirrelObject array;
.
        SquirrelObject names;
.
            SquirrelObject v = names.GetValue(n);
.

SquirrelObject returnObj = scriptFunction(Vector3(1,2,3));

.

Here is how you can convert from a SquirrelObject to a type and back, throwing an error if the type does not match:

.

// Get any bound type from a SquirrelObject. Note that Squirrel's handling of references and pointers still holds here.

.

template<class ty> static ty Get(SquirrelObject& obj) {

.

// Set any bound type to a SquirrelObject. Note that Squirrel's handling of references and pointers still holds here.

.

template|class ty| static SquirrelObject Set(ty val) {

.
    SquirrelObject obj(globalVM.GetVMHandle());
.

This function assumes that VMs are treated as objects, as proposed in another change. Effectively, anywhere globalVM.GetVMHandle() appears, any method for obtaining the VM that the SquirrelObject belongs will work.

.

While this is a static function, it could also be made into a member variable of SquirrelObject, and this is the change that would be ideal, because users could do things like this:

.

SquirrelObject t; // Created from a VM, using the static namespace or a VM object.

.

// It's also a small step from here to: SquirrelObject t(Vector3(1,2,3));

.

SquirrelObject returnObj = scriptFunction;

.

Effectively, this change would make a SquirrelObject behave like Boost::Any for any bound types. The impact on the rest of SqPlus is minimal because these functions are templated. If my knowledge of compilers isn't failing me, that means that if they aren't used, they don't get compiled, so the code growth is minimized.

.

void testSquirrelObjectSetGet(void) {

.
  SquirrelObject t(val);
.
    SquirrelObject v(Vector3(1.f,2.f,3.f)); // Pass in by value: note how many times the object is created and destroyed.
.
    SquirrelObject v(Vector3(1.f,2.f,3.f),true); // Pass in by reference instead of by copy ('true' arg). Only one temporary Vector3() is created and released.
.
      SquirrelObject v2p(pv); // This is a pointer to v's instance. It will not get freed when v2p goes out of scope.
.

} // testSquirrelObjectSetGet

.

See SquirrelObject.h for more information.

.
    else if (value->scriptObjHandle._type != OT_NULL)  Push(v, SquirrelObject(value->scriptObjHandle)); \
.
    if (value.scriptObjHandle._type != OT_NULL) Push(v, SquirrelObject(value.scriptObjHandle)); \
.
    else if (value->scriptObjHandle._type != OT_NULL)  Push(v, SquirrelObject(value->scriptObjHandle)); \
.
    if (value.scriptObjHandle._type != OT_NULL) Push(v, SquirrelObject(value.scriptObjHandle)); \
.
  SquirrelObject helloWorld = SquirrelVM::CompileBuffer("print(\"Hello World\");");
.
  SquirrelObject helloSqPlus = SquirrelVM::CompileBuffer("\
.
  SquirrelObject inst = SquirrelVM::CompileBuffer(code);
.
                SquirrelObject script = SquirrelVM::CompileBuffer(_T(
.
 inline void PopulateAncestry(HSQUIRRELVM v, SquirrelObject& instance, SQUserPointer up) {
.
        SquirrelObject objectTable = SquirrelVM::CreateTable();
.
        SquirrelObject root = SquirrelVM::GetRootTable();
.
                SquirrelObject classHeirarchyTable = root.GetValue(SQ_CLASS_HEIRARCHY_TABLE);
.
                        SquirrelObject classHierArray = classHeirarchyTable.GetValue(INT(size_t(myTypeTag)));
.
                                        SquirrelObject so = classHierArray.GetValue(i);
.
  SquirrelObject instance(ho);
.
 inline SquirrelObject RegisterClassType(HSQUIRRELVM v,const SQChar * scriptClassName, const SQChar * baseScriptClassName=0) {
.
   SquirrelObject newClass;
.
      SquirrelObject objectTable = SquirrelVM::CreateTable();
.
        SquirrelObject root = SquirrelVM::GetRootTable();
.
        SquirrelObject classHeirarchyTable; 
.
                        SquirrelObject baseClass = root.GetValue(baseScriptClassName);
.
                                SquirrelObject classHierArray = classHeirarchyTable.GetValue((INT(size_t(baseType))));
.
                                        SquirrelObject newArray = classHierArray.Clone();
.
                SquirrelObject newArray = SquirrelVM::CreateArray(0);
.
        SquirrelObject instance(ho);
.
  SquirrelObject test = SquirrelVM::CompileBuffer(_T("ih <- InterfaceHolder();"));
.
  SquirrelObject root = SquirrelVM::GetRootTable();
.
  SquirrelObject ih = root.GetValue(_T("ih"));
.

// SquirrelObject so = sa.GetObjectHandle(1);

.

// SquirrelObject so = sa.GetObjectHandle(1);

.
    SquirrelObject so = sa.GetObjectHandle(1);
.
  SquirrelObject test = SquirrelVM::CompileBuffer(_T("\
.
  SquirrelObject test = SquirrelVM::CompileBuffer(_T("\
.
  SquirrelObject test2 = SquirrelVM::CompileBuffer(_T("\
.
  SquirrelObject testInheritance2 = SquirrelVM::CompileBuffer(_T("\
.
      SquirrelObject root = SquirrelVM::GetRootTable();
.
      SquirrelObject testScriptBinding = SquirrelVM::CompileBuffer(_T("\
.
      SquirrelObject testStandardFuncs = SquirrelVM::CompileBuffer(_T(" testFunc0(); testFuncN(1.); testFuncS(\"Hello\"); "));
.
      SquirrelObject tr = SquirrelVM::GetRootTable(); // Can be any object supporting closures (functions).
.
      SquirrelObject nameSpaceTable = SquirrelVM::CreateTable();
.
      SquirrelObject testNameSpace = SquirrelVM::CompileBuffer(_T("\
.
      SquirrelObject testStaticVars = SquirrelVM::CompileBuffer(_T(" local v = Vector3(); print(\"Vector3::staticVar: \"+v.staticVar+\" Vector3::globalVar: \"+v.globalVar); v.staticVar = 0; "));
.
      SquirrelObject testConstants0 = SquirrelVM::CompileBuffer(_T(" print(\"SQ_PI*2: \"+SQ_PI_2+\" SQ_10_2: \"+SQ_10_2+\" GLOBAL_STRING: \"+GLOBAL_STRING); "));
.
      SquirrelObject testConstants1 = SquirrelVM::CompileBuffer(_T("local v = Vector3(); print(\"SQ_10: \"+v.SQ_10+\" SQ_E: \"+v.SQ_E+\" SQ_PI: \"+v.SQ_PI+\" SQ_CONST_STRING: \"+v.SQ_CONST_STRING+\" SQ_ENUM_TEST: \"+v.SQ_ENUM_TEST);" ));
.
      SquirrelObject testConstants2 = SquirrelVM::CompileBuffer(_T("local v = Vector3(); print(\"intConstant: \"+v.intConstant+\" floatConstant: \"+v.floatConstant+\" boolTrue: \"+(v.boolTrue?\"True\":\"False\")+\" boolFalse: \"+(v.boolFalse?\"True\":\"False\")+\" boolConstant: \"+(v.boolConstant?\"True\":\"False\"));" ));
.
      SquirrelObject scriptedBase = SquirrelVM::CompileBuffer(_T(" class ScriptedBase { sbval = 5551212; function multiArgs(a,...) { print(\"SBase: \"+a+val); } \n } \n ")); // Note val does not exist in base.
.
      SquirrelObject testGetInstance = SquirrelVM::CompileBuffer(_T("\
.
      SquirrelObject testClass = SquirrelVM::CompileBuffer( _T("function HealthPotionUse(Target) { \n\
.

// SquirrelObject testInheritance = SquirrelVM::CompileBuffer(_T(" class Derived extends NewTestObj { s1 = 123; \n constructor() { NewTestObj.constructor(this); }; function getParentS2() return s2; \n }; \n local t = Derived(); \n print(\"DerS2: \"+t.getParentS2()); t.multiArgs(); //t.newtestR1(\"R1in\"); "));

.

// SquirrelObject testInheritance = SquirrelVM::CompileBuffer(_T(" local t = CustomTestObj(\"sa\",321,true); \n t.val = 444; print(t.val); t.variableArgsFixedReturnType(4,5.5); t.multiArgs(1,2,3); t.newtestR1(\"R1in\"); "));

.

// SquirrelObject testInheritance = SquirrelVM::CompileBuffer(T(" class Derived extends CustomTestObj { val = 888; \n function func print(a+dVal);\n } \n local x = Derived(); print(\"x.val \"+x.val); local t = CustomTestObj(\"sa\",321,true); \n t.val = 444; print(t.val); t.variableArgsFixedReturnType(4,5.5); t.multiArgs(1,2,3); t.newtestR1(\"R1in\"); "));

.
      SquirrelObject testInheritance = SquirrelVM::CompileBuffer(_T(" class Derived extends CustomTestObj { val = 888; \n function multiArgs(a,...) { print(a+val); \n print(sbval); ::CustomTestObj.multiArgs(4); ::ScriptedBase.multiArgs(5,6,7); \n }\n } \n local x = Derived(); print(\"x.val \"+x.val); x.multiArgs(1,2,3); "));
.

// SquirrelObject testInheritance = SquirrelVM::CompileBuffer(_T(" class Derived extends CustomTestObj { val = 888; \n function multiArgs(a,...) print(a+val);\n } \n local x = Derived(); print(\"x.val \"+x.val); x.multiArgs(1,2,3); //local t = CustomTestObj(); \n t.val = 444; print(t.val); t.variableArgsFixedReturnType(4,5.5); t.multiArgs(1,2,3); t.newtestR1(\"R1in\"); "));

.
      SquirrelObject testRegV = SquirrelVM::CompileBuffer(_T(" local vec = Vector3(); print(vec.x); vec = vec.Add(vec); print(vec.x); vec = vec.Add(vec); print(vec.x); vec = vec.Add2(vec,vec); print(vec.x); local v2 = Vector3(); vec = v2.Inc(vec); print(vec.x); print(v2.x); "));
.
      SquirrelObject testReg0 = SquirrelVM::CompileBuffer(_T(" co <- CustomTestObj(\"hello\",123,true); co.varArgTypes(\"str\",123,123,\"str\"); co.varArgTypes(123,\"str\",\"str\",123); "));
.
      SquirrelObject testReg0a = SquirrelVM::CompileBuffer(_T(" print(co.varArgTypesAndCount(1,true)); print(co.varArgTypesAndCount(2,false,3.)); print(\"\\n\"); "));
.
      SquirrelObject testReg0b = SquirrelVM::CompileBuffer(_T(" print(co.noArgsVariableReturn()); print(co.noArgsVariableReturn()); print(co.noArgsVariableReturn()); print(\"\\n\"); "));
.
      SquirrelObject testReg0c = SquirrelVM::CompileBuffer(_T(" print(co.variableArgsFixedReturnType(1)); print(co.variableArgsFixedReturnType(1,2)); print(co.variableArgsFixedReturnType(1,2,3)); print(\"\\n\"); "));
.
      SquirrelObject testReg0d = SquirrelVM::CompileBuffer(_T(" co.manyArgs(111,222.2,true,\"Hello\"); print(co.manyArgsR1(333,444.3,false,\"World\")); print(\"\\n\"); "));
.
      SquirrelObject testReg1a = SquirrelVM::CompileBuffer(_T(" co <- CustomTestObj(\"hello\",123,true); co.noArgsVariableReturn(); local t = NewTestObj(\"S1in\",369,true); print(\"C1: \"+t.c1); print(\"C2: \"+t.c2); // t.c1 = 123; "));
.
        SquirrelObject testRegConstant = SquirrelVM::CompileBuffer(_T(" local t = NewTestObj(); t.c1 = 123; "));
.
      SquirrelObject testReg1 = SquirrelVM::CompileBuffer(_T(" local t = NewTestObj(); t.newtestR1(\"Hello\"); t.val = 789; print(t.val); print(t.s1); print(t.s2); t.s1 = \"New S1\"; print(t.s1); "));
.
      SquirrelObject testReg2 = SquirrelVM::CompileBuffer(_T(" local t = NewTestObj(); t.val = 789; print(t.val); t.val = 876; print(t.val); t.multiArgs(1,2,3); t.multiArgs(1,2,3,4); t.globalFunc(\"Hola\",5150,false); t.globalClassFunc(\"Bueno\",5151,true); "));
.
      SquirrelObject testReg3 = SquirrelVM::CompileBuffer(_T(" test(); local rv = testR1(\"Hello\"); print(rv); "));
.
      SquirrelObject testReg4 = SquirrelVM::CompileBuffer(_T(" print(\"\\nMembers:\"); testObj_newtest1(); testObj_newtest2(); print(testObj_newtestR1(\"Hello Again\")); "));
.
      SquirrelObject defCallFunc = SquirrelVM::CompileBuffer(_T(" function callMe(var) { print(\"I was called by: \"+var); return 123; }"));
.
      SquirrelObject main = SquirrelVM::CompileBuffer(_T("table1 <- {key1=\"keyVal\",key2 = 123};\n if (\"key1\" in table1)\n print(\"Sq: Found it\");\n else\n print(\"Sq: Not found\");"));
.
      SquirrelObject table1 = root.GetValue(_T("table1"));
.
      SquirrelObject array = SquirrelVM::CreateArray(10);
.
      SquirrelObject so1 = array.ArrayPop();   // Retrieve the popped value.
.
      SquirrelObject arrayr = array.Clone(); // Get a copy as opposed to another reference.
.
      SquirrelObject define_printArray = SquirrelVM::CompileBuffer(_T(" function printArray(name,array) { print(name+\".len() = \"+array.len()); foreach(i, v in array) if (v != null) { if (typeof v == \"bool\") v = v ? \"true\" : \"false\"; print(\"[\"+i+\"]: \"+v); } } "));
.
      SquirrelObject test = SquirrelVM::CompileBuffer(_T(" printArray(\"array\",array); printArray(\"arrayr\",arrayr); "));