Skip to content

Instantly share code, notes, and snippets.

View fowlmouth's full-sized avatar
🦃

Tim E fowlmouth

🦃
  • United States of America
View GitHub Profile
@fowlmouth
fowlmouth / unzip.rb
Last active December 16, 2015 12:19
class Array
def unzip
#r = Array.new(self[0].size) {[]}
#each { |arr|
each_with_object(Array.new(self[0].size){[]}) {|arr, r|
arr.each_with_index { |x, i|
r[i] << x
}
}
@fowlmouth
fowlmouth / components.rb
Created April 23, 2013 00:33
ruby mini component system
require'gosu';include Gosu
class Component
class << self
# @field should be set for each base class,
# entities that include this component or a derivative
# respond to this as a message
def field() @field or superclass.field end
def iface() (@interface or []) + (superclass.iface rescue []) end
proc curry[A, Ret] (
func: proc(someA: A): Ret,
valueA: A): proc: Ret =
return proc: Ret = func(valueA)
proc curry[A,B, Ret] (
func: proc(someA: A, someB: B): Ret,
valueA: A): proc(someB: B): Ret =
return proc(someB: B): Ret = func(valueA, someB)
proc curry[A,B,C, Ret] (
@fowlmouth
fowlmouth / comp3.nim
Last active December 16, 2015 22:29
import fowltek/vector_math
type
TVector2f = TVector2[float]
TPos = TVector2f
TVel = TVector2f
PSprite = ref object
@fowlmouth
fowlmouth / entitty.nim
Last active December 16, 2015 23:49
nimrod component/entity system
## entitty has been moved to the fowltek package
import fowltek/entitty
entitty_imports
import fowltek/vector_math
type Pos = Tvector2[float]
type Vel = object
vec: TVector2[float]
Pos.setInitializer proc(x: PEntity) =
import fowltek/entitty, fowltek/sdl2/engine
entitty_imports
import_all_sdl2_modules
import fowltek/vector_math
type TVector2f* = TVector2[float]
proc getPos* : TVector2f {.unicast.}
proc update* (dt: float) {.multicast.}
proc draw* (R: PRenderer) {.unicast.}
import macros
macro foo: stmt =
var y = newIntLitNode(0)
result = quote do:
let x = `y`
result.treerepr.echo
if result[0][0][0].kind != nnkIdent:
quit "Invalid node kind "& $result[0][0][0].kind
import macros
from strutils import format
macro constStr* (name; str: expr[string]): stmt {.immediate.}=
##need a check for top level statement??
result = """{.emit: "prog_char $1_data[] PROGMEM = \"$2\"; ".}
var $1_data {.importc, nodecl.}: array[$3, char]
template $1: cstring = $1_data[0].addr""".format(name, str, str.strval.len).parseStmt
result.repr.echo
@fowlmouth
fowlmouth / lua52.nim
Last active December 18, 2015 06:08
lua 5.2
#
#* $Id: lua.h,v 1.283 2012/04/20 13:18:26 roberto Exp $
#* Lua - A Scripting Language
#* Lua.org, PUC-Rio, Brazil (http://www.lua.org)
#* See Copyright Notice at the end of this file
#
const
LUA_VERSION_MAJOR* = "5"
LUA_VERSION_MINOR* = "2"
LUA_VERSION_NUM* = 502