Skip to content

Instantly share code, notes, and snippets.

@rofl0r
Created August 11, 2010 23:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rofl0r/520029 to your computer and use it in GitHub Desktop.
Save rofl0r/520029 to your computer and use it in GitHub Desktop.
XString: class {
data : Char*
size : SizeT
init: func (src: Char*, =size) {
data = gc_malloc(size)
memcpy (data, src, size)
}
equals?: func -> Bool { false }
}
operator implicit as (s: XString) -> Char* {
s data
}
operator implicit as (c: Char*) -> XString {
XString new (c, strlen(c))
}
operator [] (string: XString, index: SizeT) -> Char {
( string data + index )@
}
operator []= (string: XString, index: SizeT, value: Char) {
(string data + index)@ = value
}
main: func {
x := XString new ( "xxxx" as Char*, 4)
x[1] = 'y'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment