Skip to content

Instantly share code, notes, and snippets.

// Usage
new target("all", |task|
task compile("file.ooc", compile options => ["run", set("dist", "distDir")])
. print("Compiled, now cleaning")
. execute(get target("clean"))
)
new target("clean", |task|
task select("rock_tmp", ".libs") delete()
@alexnask
alexnask / gist:2769013
Created May 22, 2012 13:22
Simple Http class for file grabbing
include time, stdlib
import os/Process
import net/TCPSocket
import threading/Thread
import structs/[ArrayList, HashMap, HashBag, Bag]
import text/json
import io/[File, FileWriter, Reader]
time: extern func(Pointer) -> UInt
@alexnask
alexnask / gist:2776491
Created May 23, 2012 17:22
Processes!
makeVideo: func(music, image, dest: File, name: String) {
// just launch ffmpeg :D
"Making video..." println()
process := Process new(["ffmpeg", "-loop_input", "-shortest", "-y", "-i", image getAbsolutePath(), "-i", music getAbsolutePath(), "-acodec", "copy", "-vcodec", "mjpeg", dest getChild(name) getAbsolutePath()])
process setStdout(Pipe new()) . setStderr(Pipe new())
"ffmpeg exited with status %d" format(process execute()) println()
"Made video!" println()
}
@alexnask
alexnask / gist:2877174
Created June 5, 2012 19:25
Operator non-inheritance
Foo: class {}
Bar: class extends Foo {}
operator + <T> (left: Foo, right: T) {
"OHAI" println()
}
bar: Bar
bar + 42
@alexnask
alexnask / test.c
Created June 8, 2012 11:14
Slice them arrays!
void array_range____OP_IDX_T__star_Range__T__star(uint8_t* __genericReturn1, lang_types__Class* T, uint8_t* data, lang_Numbers__Range range) {
lang_Numbers__Int size = range.max - range.min;
uint8_t* ret = ((uint8_t*) (lang_Memory__gc_malloc(size * T->size)));
{
lang_Numbers__Int i;
for (i = 0; i < size; i++) {
lang_Memory__memcpy(&(ret[i * T->size]), &(data[(range.min + i) * T->size]), T->size);
}
}
@alexnask
alexnask / c_version.c
Created June 8, 2012 16:53
C version of strange ooc generics bug
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
typedef struct {
int min;
int max;
} Range;
void slice(uint8_t* genReturn, uint8_t* data, Range range) {
/* test source file, generated with rock, the ooc compiler written in ooc */
#include <./test.h>
#include <sdk/lang/String.h>
#include <sdk/lang/BufferIterator.h>
#include <sdk/lang/Abstractions.h>
#include <sdk/lang/System.h>
#include <sdk/lang/Format.h>
#include <sdk/lang/IO.h>
#include <sdk/lang/types.h>
; This is a comment. Only when the line starts with it though
; Set the variable "name" to "SampleTest"
; Variable names are case insensitive
Name: SampleTest
Source: foo.ooc
; This is special syntax to set a variable to a block of text
; This way you can have multi-line values
Compilation-stdout-output !>>
@alexnask
alexnask / funky.ooc
Created June 21, 2012 16:52
Maybe and Either
MaybeState: enum {
None,
Some
}
Maybe: class <T> {
_value: T
value: T {
get {
if(state == MaybeState None) raise("No value!")
@alexnask
alexnask / Symbol.ooc
Created July 3, 2012 11:55
ooc symbol implementation
import structs/ArrayList
Symbol: class {
value: String
table: static ArrayList<This>
new: static func(.value) -> const This {
if(!table) table = ArrayList<This> new()