Skip to content

Instantly share code, notes, and snippets.

View kg's full-sized avatar

Katelyn Gadd kg

View GitHub Profile
@kg
kg / MultiDimArrays.cs
Created June 7, 2011 08:26
JSIL Code Sample: Multidimensional Arrays
using System;
public static class Program {
public static void Main (string[] args) {
// [y, x], not [x, y]!
var a = new string[5, 10];
var h = a.GetLength(0);
var w = a.GetLength(1);
for (var y = 0; y < h; y++)
@kg
kg / 1.cs
Created June 18, 2011 12:20
Performance Challenges in Compiling Code to JavaScript
float elapsed = ...;
Vector3 position = object1.Position, velocity = object1.Velocity;
Vector3 nextPosition = position + (velocity * elapsed);
GraphicsContext.DrawLine(position, nextPosition);
Program.ReturnArgument = function (arg) {
return arg;
};
Program.Main = function (args) {
var a = new CustomType();
a._ctor(1);
var b = Program.ReturnArgument(a).MemberwiseClone();
a.Value = 2;
System.Console.WriteLine("a={0}, b={1}", a, b);
b = Program.ReturnArgument(a).MemberwiseClone();
@kg
kg / JSIL.Core.js
Created July 8, 2011 19:15
JSIL.Core
"use strict";
if (typeof (JSIL) !== "undefined")
throw new Error("JSIL.Core included twice");
var JSIL = {
__FullName__ : "JSIL"
};
// Safari does not provide Function.prototype.bind, and we need it.
@kg
kg / gist:1379915
Created November 20, 2011 07:00
Inferus RenderEntities
public void RenderEntities (DrawFlags flags) {
if (flags == DrawFlags.None)
return;
var bounds = Camera.Bounds;
SpatialCollection<RuntimeEntity>.ItemInfo current;
using (var e = RuntimeLevel.Entities.GetItemsFromBounds(bounds))
while (e.GetNext(out current))
current.Item.Draw(flags);
}
@kg
kg / input.cs
Created December 3, 2011 17:25
Replacing type names with arbitrary JavaScript
[JSReplacement("UnqualifiedTypeName")]
public static class MyClass {
public static string StringField = "StringField";
public static string StringProperty {
get;
set;
}
public static string GetString () {
return "MyClass";
// Program
public static void Main(string[] args)
{
int i = 0;
while (i < args.Length)
{
string text = args[i];
string text2 = text;
if (text2 == null)
{
@kg
kg / pretty
Created February 20, 2012 01:58
Func<FieldDefinition, bool> isFieldIgnored = (f) => {
IMemberInfo memberInfo;
if (typeInfo.Members.TryGetValue(MemberIdentifier.New(f), out memberInfo))
return memberInfo.IsIgnored;
else
return true;
};
var structFields =
(from field in typedef.Fields
var methodGroups = (from kvp in Members where kvp.Key.Type == MemberIdentifier.MemberType.Method
let m = (MethodInfo)kvp.Value
group m by new {
m.Member.Name,
m.Member.GenericParameters.Count,
m.IsStatic
} into mg
where mg.Count() > 1
select mg).ToArray();
protected TaskFn GetEntityPlacer (string entityType) {
return () => {
PlaceEntity(GetMousePosition(true), entityType);
return null;
};
}