Skip to content

Instantly share code, notes, and snippets.

View kg's full-sized avatar

Katelyn Gadd kg

View GitHub Profile
using System;
public static class Program {
public static void Main (string[] args) {
int x = 1;
string y = "y";
Func<string> a = () => {
return String.Format("x={0}, y={1}", x, y);
};
@kg
kg / YieldReturn.cs
Created May 7, 2011 08:23
JSIL test case (iterator functions)
using System;
using System.Collections;
using System.Collections.Generic;
public static class Program {
public static IEnumerable<int> OneToNine {
get {
for (int i = 0; i < 10; i++)
yield return i;
}
// Microsoft.Xna.Framework.Vector2
public static Vector2 Transform(Vector2 value, Quaternion rotation)
{
float num = rotation.X + rotation.X;
float num2 = rotation.Y + rotation.Y;
float num3 = rotation.Z + rotation.Z;
float num4 = rotation.W * num3;
float num5 = rotation.X * num;
float num6 = rotation.X * num2;
float num7 = rotation.Y * num2;
JSIL.MakeType = function (baseType, namespace, localName, fullName, isReferenceType) {
if (typeof (namespace[localName]) != "undefined")
throw new Error("Duplicate definition of type " + fullName);
var initType;
var ctor = function () {
JSIL.InitializeStructFields(this, localName);
if (typeof (initType) != "undefined")
initType();
@kg
kg / BatchedLoader.cs
Created May 19, 2011 08:21
Solving Problems With Asynchrony #4
protected IEnumerator<object> TextureLoaderTask () {
var sleep = new Sleep(0.5); // Wait half a second for work items to build up.
var batch = new List<PendingTextureLoad>();
while (true) {
// Pull a single work item from the queue. Our task will be put to sleep if
// the queue is empty.
{
var f = TextureLoadQueue.Dequeue();
yield return f;
@kg
kg / ForEach.cs
Created June 7, 2011 07:04
JSIL Code Sample: ForEach
using System;
using System.Collections.Generic;
public static class Program {
public static void Main (string[] args) {
var array = new[] { 1, 2, 4, 8, 16 };
foreach (var i in array)
Console.WriteLine(i);
@kg
kg / MulticastDelegates.cs
Created June 7, 2011 08:12
JSIL Code Sample: MulticastDelegates
using System;
public static class Program {
public static void Main (string[] args) {
Action<int> a =
(i) => Console.WriteLine("a({0})", i);
Action<int> b =
(i) => Console.WriteLine("b({0})", i);
Action<int> c = (Action<int>)Delegate.Combine(a, b);
@kg
kg / LambdaRefParameters.cs
Created June 7, 2011 08:13
JSIL Code Sample: ref parameters
using System;
public static class Program {
public static void Increment (ref int x) {
x += 1;
}
public static void Main (string[] args) {
Func<int, int> inc = (i) => {
Increment(ref i);
@kg
kg / IndexBuiltinByName.cs
Created June 7, 2011 08:23
JSIL Code Sample: Verbatim JavaScript
using System;
using JSIL;
public static class Program {
public static void Main (string[] args) {
const string pri = "pri";
string nt = "nt";
var p = Builtins.Global[pri + nt] as dynamic;
if (p != null)
@kg
kg / DisplayClassFieldNames.cs
Created June 7, 2011 08:25
JSIL Code Sample: Closures
using System;
public static class Program {
public static void Main (string[] args) {
int x = 1;
string y = "y";
Func<string> a = () => {
return String.Format("x={0}, y={1}", x, y);
};