1
DOH (Dave's Object Hack)
5
DOH is a small C library that provides a number of simple yet powerful
6
data structures. The data structures are built around a dynamic typing
7
model in which any given object is allowed to support one or more
8
classes of operations. Furthermore, a simple garbage collection
9
scheme and a variety of interesting library methods are available.
10
All and all, the operation of DOH makes massive abuse of the C type
11
system and would probably make the language purists scream and
12
performance addicts run away in horror. However, I really don't
13
care--so there! However, for the rest of us, DOH is actually kind of
14
fun to use. This is only a short description of the methods and is no
15
way meant to be exhaustive.
17
Common Operations (for all types)
18
---------------------------------
19
Delete(obj) Decrease the reference count and destroy if zero
20
Copy(obj) Make a copy of an object.
21
Clear(obj) Clear an object.
22
Setscope(obj) Set scope of an object (guru's only)
23
Str(obj) Create a string representation of obj.
24
Data(obj) Return pointer to raw data in an object
25
Char(obj) Convert to a char *
26
Len(obj) Length of an object
27
Hash(obj) Hash value (used for mapping)
28
Cmp(obj1,obj2) Compare two objects.
29
Name(obj) Return the object name
30
First(obj) Return first object (iterator)
31
Next(obj) Return next object
32
Dump(obj,out) Serialize on out
33
Load(in) Unserialize from in
35
Mapping Operations (for hash table behavior)
36
--------------------------------------------
37
Getattr(hash,key) Get an attribute
38
Setattr(hash,key,value) Set an attribute
39
Delattr(hash,key) Delete an attribute
40
Firstkey(hash) Get first key
41
Nextkey(hash) Get next key
42
First(hash) Get first object
43
Next(hash) Get next object
44
GetInt(hash,key) Get attribute as an 'int'
45
SetInt(hash,key,ivalue) Set attribute as an 'int'
46
GetDouble(hash,key) Get attribute as a 'double'
47
SetDouble(hash,key,dvalue) Set Attribute as a 'double'
48
GetChar(hash,key) Get attribute as a 'char *'
52
Getitem(list,index) Get an item
53
Setitem(list,index,val) Set an item
54
Delitem(list,index,val) Delete an item
55
Insert(list,index,val) Insert an item
56
Append(list,val) Append to end
57
Push(list,val) Insert at beginning
61
Read(obj,buffer,len) Read data
62
Write(obj,buffer,len) Write data
63
Getc(obj) Get a character
64
Putc(ch,obj) Put a character
65
Ungetc(ch,obj) Put character back on input stream
66
Seek(obj,offset,whence) Seek
67
Tell(obj) Return file pointer
72
Replace(obj, orig, rep, flags) Replace occurences of orig with rep.
73
Chop(obj) Remove trailing whitespace
75
flags is one of the following:
83
Call(obj, args) Perform a function call with arguments args.
85
Miscellaneous library functions
86
-------------------------------
87
NewScope() Create a new scope
88
DelScope(s) Delete scope s
89
Readline(in) Read a line of input from in
90
Printf(out,fmt,...) Formatted output
91
DohEncoding(name, fn) Register a format encoding for Printf
93
Currently Available datatypes
94
------------------------------
95
NewString(char *initial) Strings
98
NewVoid(void *ptr, void (*del)(void *)) Void
99
NewFile(char *file, char *mode) File
100
NewCallable(DOH *(*func)(DOH *, DOH *)) Callable object
105
1. All objects are of type 'DOH *'
106
2. When in doubt, see rule (1)
107
3. In certain cases, DOH performs implicit conversions
108
of 'char *' to an appropriate DOH string representation.
109
For operations involving files, DOH works with many
110
kinds of objects including FILE *, DOH File objects,
111
and DOH strings. Don't even ask how this works.
113
4. More complete documentation is forthcoming.