Skip to content

Instantly share code, notes, and snippets.

View mbolt35's full-sized avatar
:octocat:
Code, code, code...

Matt Bolt mbolt35

:octocat:
Code, code, code...
View GitHub Profile
@mbolt35
mbolt35 / ArrayClass.cpp
Created April 24, 2012 01:48
Vector Dynamic Memory Allocation
// Allocation for Array
ArrayObject* ArrayClass::newarray(Atom* argv, int argc)
{
ArrayObject *inst = newArray(argc);
for (uint32 i=0; i<uint32(argc); i++) {
inst->setUintProperty(i, argv[i]);
}
@mbolt35
mbolt35 / Foo.coffee
Created May 1, 2012 14:53
CoffeeScript Global Class
# Defining a class globally can be done like this:
class Foo
constructor: (@name) ->
this.Foo = Foo;
# Or like this...
this.Foo = class Foo
constructor: (@name) ->
// These produce the same Array *structure*, they are not
// strictly equivalent (===)
var oneWay:Array = new Array(1, 2, 3);
var anotherWay:Array = [ 1, 2, 3 ];
// Each of these result with the same Vector.<int>
// *structure*, however they are not strictly
// equivalent (===).
var v1:Vector.<int> = new Vector.<int>(3);
v1[0] = 1; v1[1] = 2; v1[2] = 3;
var arr:Array = [ 1, 2, 3 ];
var vec:Vector.<int> = Vector.<int>(arr);
trace(vec);
// Outputs: 1,2,3
public static function vectorToArray(vector:*):Array {
var result:Array = [];
for (var i:int = 0; i < vector.length; ++i) {
result[i] = vector[i];
}
return result;
}
var vec:Vector. = new <int>[ 1, 2, 3 ];
var arr:Array = function(v:Vector.<int>):Array {
var result:Array = [];
for (var i:int = 0; i < v.length; ++i) {
result[i] = v[i];
}
return result;
}(vec);
// This constant is set to the fully qualified class name for Vector
private static const VECTOR_CLASS:String = "__AS3__.vec::Vector";
// Use flash.utils.describeType() on the input, and verify type
// of the object is a Vector class. This is probably fairly
// expensive, a valid point to my argument.
public static function isVector(vector:*):Boolean {
var type:String = flash.utils.describeType(vector).@name;
return type.indexOf(VECTOR_CLASS) != -1;
}
public static function vectorToArray(vector:*):Array {
if (!isVector(vector)) {
throw new ArgumentError("Illegal argument, non-Vector for use with vectorToArray().");
}
var result:Array = [];
for (var i:int = 0; i < vector.length; ++i) {
result[i] = vector[i];
}
return result;
var arr:Array = [ 1, 2, 3 ];
var arr2:Array = [ 3, 2, 1 ];
var result:Array = arr.concat(arr2);
trace(result);
// Outputs: 1,2,3,3,2,1
// ...
var arr3:Array = [ 9, 8, 7 ];
result = arr.concat(arr2, arr3);
trace(result);
// Outputs: 1,2,3,3,2,1,9,8,7