Archive for March, 2013

Notes and Differences between Squirrel and JavaScript

Saturday, March 9th, 2013

Here are my notes on Squirrel and JavaScript.

  • JS: Number, String, Array, Object (Table), Function, Null (object named null), Undefined
  • SQ: Integer, Float, String, Array, Table (Object), Function, Null (null), Class, ClassInstance, Generator, Thread, Weak Reference, UserData, UserPointer
  • JS: false, undefined, null, 0, NaN, “” SQ: false, null, 0, 0.0 (“” untested)
  • JS: var MyVariable = Value; /*Global*/ SQ: MyVariable <- Value; /*Root Table*/
  • JS: {var MyVariable;} /* Undefined, Local */ SQ: {local MyVariable;}
  • Squirrel has Integers AND Floats! JavaScript is only Numbers (Doubles).
  • JS: Use JQuery or MooTools SQ: local MyCopy = clone Original;
  • SQ: The .weakref() method of Integers, Floats, Booleans does not return a reference, but instead just returns the values (native). Using it on Tables, Arrays, Strings and Functions does return a weak reference.
  • JS: alert( typeof(MyString) ) /* “String” */ SQ: print( typeof MyString ) /* “String” */
  • JS: var Code = eval(“/*code*/”); SQ: local Code = compilestring(“/*code*/”);
  • JS: console.log(“Hey”); SQ: error(“Hey”);
  • JS: arguments.callee (deprecated) SQ: print( callee() ); /*currently running closure*/
  • JS: complicated SQ: print( _version_ + ” (” + _versionnumber_ + “)” ); /* 304 for 3.04 */
  • SQ: print( “char: ” + _charsize_ + ” int: ” + _intsize + ” float: ” + _floatsize_ );
  • Strings and Numbers (mostly Strings)

  • JS: var MyString = “Hello”; SQ: local MyString = “Hello”;
  • JS: MyString.toString() SQ: MyString.tostring()
  • JS: var Num=”5″; Num = +Num; SQ: local Num=”5″; Num = Num.tointeger(); or Num.tofloat();
  • JS: MyString.toLowerCase().toUpperCase(); SQ: MyString.tolower().toupper();
  • JS: MyString.length; SQ: MyString.len()
  • JS: MyString.slice( StartPos [, Count] ); or substr or substring SQ: MyString.slice( StartPos [, Count] );
  • JS: if ( MyString.indexOf(“Hey”[,StartPos]) != -1 ) {} SQ: if ( MyString.find(“Hey”[,StartPos]) != null ) {}
  • JS: if ( MyString.lastIndexOf(“Hey”[,StartPos]) != -1 ) {} SQ: ???
  • JS: MyString.search(…) has no optional StartPos parameter.
  • JS: MyString.replace( “Hello”, “Halo” ); SQ: ???
  • JS: var FirstLetter = MyString[0]; SQ: local FirstLetter = MyString[0]
  • JS: var Str = “Hello” + “World”; SQ: local Str = “Hello” + “World”;
  • JS: var MyStr = String.fromCharCode(65); /*A*/ SQ: local MyStr = (65).tochar(); /*Ints or Floats*/
  • SQ: foreach can be used on strings to iterate over all characters
  • Arrays

  • JS: var MyArray = []; SQ: local MyArray <- [];
  • JS: var MyArray = [1,”hello”,3]; SQ: local MyArray <- [1,"hello",3];
  • JS: var MyArray = Array(10); /*10 elements*/ SQ: local MyArray = array(10 [,fill]);
  • JS: MyArray.push(value); SQ: MyArray.push(value) or append /*push_back*/
  • JS: var Value = MyArray.pop(); SQ: local Value = MyArray.pop() /*pop_back*/
  • JS: var Value = MyArray.shift(); SQ: local Value = MyArray[0]; MyArray.remove(0); /*pop_front*/
  • JS: var Val = MyArray[MyArray.length-1]; SQ: local Val = MyArray.top() /*pop_back w/o pop*/
  • JS: MyArray = Array.concat(MyArray,Array2); SQ: MyArray.extend( Array2 ) /*push_back an array*/
  • JS: MyArray.splice(Index,0,Value[,Value2,…]); SQ: MyArray.insert( Index, Value );
  • JS: MyArray.splice(Index,1); /* How Many */ SQ: MyArray.remove( Index );
  • JS: MyArray.length = Size; (unconfirmed) SQ: MyArray.resize( Size [,Fill] );
  • JS: MyArray.length = 0; (unconfirmed) SQ: MyArray.clear();
  • JS: MyArray.sort() SQ: MyArray.Array.sort( [CompareFunction] );
  • JS: MyArray.reverse(); SQ: MyArray.reverse();
  • JS: var MySlice = MyArray.slice(Start [,End]); SQ: local MySlice = MyArray.slice(Start [,End]);
  • JS: for(var idx=0;idxSQ: MyArray.apply( MyFunction );
  • SQ: MyArray.reduce( … ) /* leave All but one, call function on removed */
  • SQ: MyArray.filter( ) /* make new list based on all that match pattern */
  • Objects (JS) and Tables (SQ)

  • JS: var MyObject = {}; SQ: local MyTable = {};
  • JS: var MyObject = {}; SQ: MyTable <- {};
  • JS: var MyObject.Member = Value; SQ: MyTable.Member <- Value; /* Create Only. Can use = after */
  • JS: delete MyObject.Member; SQ: delete MyTable.Member; /* returns old value */
  • JS: if ( (typeof MyTable.Member) != “undefined” ) Has(); SQ: if ( “Member” in MyTable ) Has();
  • JS: alert( MyObject.join() ); /* output contents to string */ SQ: ??? (do a loop)
  • JS: no but you can make a function SQ: print( MyTable.len() );
  • JS: nope SQ: MyTable.clear();
  • SQ: MyTable.rawget(key) /* Get w/o delegation */
  • SQ: MyTable.rawset(key,value) /* Set w/o delegation. Creates if doesn’t exist */
  • SQ: MyTable.rawdelete() /* Deletes and returns value w/o delegation. null if doesn’t exist */
  • SQ: MyTable.rawin(key) /* true if exists (same as in operator) w/o delegation */
  • SQ: MyTable.setdelegate( MyDelegate ) /* null clears */
  • SQ: MyTable.getdelegate() /* returns delegate, or null if none */
  • Functions

  • JS: function MyFunc() { } SQ: function MyFunc() { }
  • JS: function MyFunc(arg1,arg2) { } SQ: function MyFunc(arg1,arg2) { }
  • JS: var MyFunc = function() { } SQ: local MyFunc = function() { }
  • JS: none SQ: if ( (@(arg1,arg2) arg1 + arg2) > 0 ) {…}
  • JS: MyFunc.call(MyThis [,args,…]); SQ: MyFunc.call(MyThis [,args,…]);
  • SQ: pcall(…) ignores error callback. acall(…) takes an array; arg[0] is this. pacall is array pcall.
  • SQ: local BoundFunc = MyFunc.bindenv(OtherEnv); /* replaces .this with OtherEnv (Table) */
  • SQ: MyFunc.getinfos() returns an object containing information about a function.
  • TODO: Class Inheritance

  • SQ: if ( MyInstance instanceof MyClass ) {…}
  • SQ: Metamethods: _add, _sub, _mul, _div, _unm, _modulo, _set, _get, _typeof, _nexti, _cmp, _call, _delslot, _tostring, _newmember, _inherited
  • TODO: Generators
    yield, resume

    TODO: Coroutines (i.e. N/A JS, but sort of. TODO C++ Coroutine)

    TODO: Try Catch

The New Cards

Friday, March 1st, 2013

CardPhoto

Ordered from Morning Print. White plastic, thin, nice and vibrant, and practically indestructible!