[Wheat-developer] Fwd: object-oriented bash scripts (second try)
Status: Pre-Alpha
Brought to you by:
mark_lentczner
|
From: Kragen S. <ksi...@co...> - 2005-04-21 05:07:09
|
This is slightly off-topic. I had forgotten about this hack I made a few years ago: http://lists.canonical.org/pipermail/kragen-hacks/2002-February/000317.html I built a prototype-oriented object system based on Self (you know, a slot foo gives you getter and setter methods foo: and foo) with a hierarchical memory system using symbolic links for non-hierarchical references, including a symbolic link in each object to its prototype. This was inspired by Martin Hinsch's hack "woosh", which is now found at http://132.187.24.1/~martin/woosh/ I didn't build a language for it, though. I used bash. Here's the definition of "basicobject/getprop": #!/bin/bash -e # Intended to be called by other names. defprop makes symlinks to this script. cat "$METHODOBJ/.$METHOD" And here's "basicobject/new": #!/bin/bash -e # 'new' --- normal way to make a new object like an existing one if [[ $# -lt 2 ]]; then echo "Usage: oo obj new dest [args...] creates a copy of 'obj' in 'dest'.">&2 exit 5 fi obj="$1" dest="$2" shift; shift if [[ -e "$dest" ]] ; then echo "$dest already exists" >&2; exit 5; fi trap 'rm -rf "$dest"' EXIT cp -a "$obj" "$dest" oo "$dest" init "$@" trap '' EXIT Pretty creepy, eh? Wheat has a lot more promise as a programming environment because it has a reasonable programming language and stands a chance of having decent performance. Still, it's kind of weird that I was thinking along these lines in 2002, and I'd completely forgotten about it by late 2004 when Mark came along. Some unfortunate person in New York searched Google for "object oriented bash shell" and found this post, which reminded me that it happened. It's too bad all the code is trapped in the antiquated uuencode format... |