2002-08-03 06:04:00 +00:00
|
|
|
/*
|
|
|
|
#FILENAME#
|
|
|
|
|
|
|
|
#DESCRIPTION#
|
|
|
|
|
2003-04-13 22:07:58 +00:00
|
|
|
Copyright (C) 2003 #AUTHOR#
|
2002-08-03 06:04:00 +00:00
|
|
|
|
|
|
|
Author: #AUTHOR#
|
|
|
|
Date: #DATE#
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
2002-08-08 09:20:00 +00:00
|
|
|
$Id$
|
2002-08-03 06:04:00 +00:00
|
|
|
*/
|
|
|
|
|
2003-04-13 22:07:58 +00:00
|
|
|
#ifndef __gib_h
|
|
|
|
#define __gib_h
|
2002-10-16 04:59:34 +00:00
|
|
|
|
2003-04-13 22:07:58 +00:00
|
|
|
// Dependencies
|
|
|
|
|
|
|
|
#include "QF/dstring.h"
|
|
|
|
#include "QF/cbuf.h"
|
2003-09-11 06:03:13 +00:00
|
|
|
#include "QF/hash.h"
|
|
|
|
#include "QF/llist.h"
|
|
|
|
|
|
|
|
// Object interface
|
|
|
|
|
|
|
|
typedef void (*gib_reply_handler) (int argc, const char **argv, void *data);
|
|
|
|
|
|
|
|
typedef struct gib_signal_s {
|
|
|
|
const char *name;
|
|
|
|
struct gib_object_s *receiver;
|
|
|
|
struct gib_slot_s *slot;
|
|
|
|
} gib_signal_t;
|
|
|
|
|
|
|
|
typedef struct gib_slot_s {
|
|
|
|
const char *mesg;
|
|
|
|
struct gib_object_s *sender;
|
|
|
|
struct gib_signal_s *signal;
|
|
|
|
} gib_slot_t;
|
|
|
|
|
|
|
|
typedef struct gib_object_s {
|
|
|
|
struct gib_class_s *class;
|
|
|
|
hashtab_t *methods;
|
|
|
|
void **data;
|
|
|
|
unsigned long int handle, refs;
|
2003-10-19 00:51:47 +00:00
|
|
|
hashtab_t *signals, *vars;
|
2003-09-11 06:03:13 +00:00
|
|
|
llist_t *slots;
|
2003-09-21 00:30:47 +00:00
|
|
|
const char *handstr;
|
2003-09-11 06:03:13 +00:00
|
|
|
} gib_object_t;
|
|
|
|
|
|
|
|
typedef struct gib_message_s {
|
|
|
|
int argc;
|
|
|
|
const char **argv;
|
|
|
|
gib_reply_handler reply;
|
|
|
|
void *replydata;
|
|
|
|
} gib_message_t;
|
|
|
|
|
|
|
|
typedef struct gib_method_s {
|
|
|
|
const char *name;
|
2003-09-11 08:51:44 +00:00
|
|
|
int (*func) (struct gib_object_s *obj, struct gib_method_s *method,
|
|
|
|
void *data, gib_object_t *sender, gib_message_t message);
|
2003-09-11 06:03:13 +00:00
|
|
|
struct gib_method_s *parent;
|
|
|
|
struct gib_class_s *class;
|
|
|
|
void *data;
|
|
|
|
} gib_method_t;
|
|
|
|
|
2003-09-11 08:51:44 +00:00
|
|
|
typedef int (*gib_message_handler) (gib_object_t *obj, gib_method_t *method,
|
|
|
|
void *data, gib_object_t *sender, gib_message_t message);
|
2003-09-11 06:03:13 +00:00
|
|
|
typedef void * (*gib_obj_constructor) (gib_object_t *obj);
|
|
|
|
typedef void (*gib_obj_destructor) (void *data);
|
|
|
|
|
|
|
|
typedef struct gib_class_s {
|
|
|
|
const char *name;
|
|
|
|
hashtab_t *methods, *class_methods;
|
|
|
|
gib_obj_constructor construct, class_construct;
|
|
|
|
gib_obj_destructor destruct;
|
|
|
|
unsigned int depth;
|
|
|
|
struct gib_object_s *classobj;
|
|
|
|
struct gib_class_s *parent;
|
2003-09-21 00:30:47 +00:00
|
|
|
llist_t *children;
|
2003-09-11 06:03:13 +00:00
|
|
|
} gib_class_t;
|
|
|
|
|
|
|
|
typedef struct gib_methodtab_s {
|
|
|
|
const char *name;
|
|
|
|
gib_message_handler func;
|
|
|
|
void *data;
|
|
|
|
} gib_methodtab_t;
|
|
|
|
|
|
|
|
typedef struct gib_classdesc_s {
|
|
|
|
const char *name;
|
|
|
|
const char *parentname;
|
|
|
|
gib_obj_constructor construct, class_construct;
|
|
|
|
gib_obj_destructor destruct;
|
|
|
|
struct gib_methodtab_s *methods, *class_methods;
|
|
|
|
} gib_classdesc_t;
|
|
|
|
|
2003-09-11 08:51:44 +00:00
|
|
|
#define GIB_ForwardToSuper(mesg,obj,method) ((method)->parent->func ((obj), \
|
|
|
|
(method)->parent, \
|
|
|
|
(obj)->data[(method)->parent->class->depth], \
|
|
|
|
(obj), (mesg)))
|
2003-09-11 06:03:13 +00:00
|
|
|
|
|
|
|
void GIB_Class_Create (gib_classdesc_t *desc);
|
|
|
|
gib_object_t *GIB_Object_Create (const char *classname, qboolean classobj);
|
|
|
|
void GIB_Object_Destroy (gib_object_t *obj);
|
|
|
|
void GIB_Object_Incref (gib_object_t *obj);
|
|
|
|
void GIB_Object_Decref (gib_object_t *obj);
|
2003-09-11 08:51:44 +00:00
|
|
|
int GIB_Send (gib_object_t *obj, gib_object_t *sender, int argc, const char **argv, gib_reply_handler reply, void *replydata);
|
|
|
|
int GIB_SendToMethod (gib_object_t *obj, gib_method_t *method, gib_object_t
|
|
|
|
*sender, int argc, const char **argv, gib_reply_handler reply,
|
|
|
|
void *replydata);
|
2003-09-21 00:30:47 +00:00
|
|
|
void GIB_Reply (gib_object_t *obj, gib_message_t mesg, int argc, const char
|
|
|
|
**argv);
|
2003-09-11 06:03:13 +00:00
|
|
|
gib_object_t *GIB_Object_Get (const char *id);
|
|
|
|
void GIB_Object_Signal_Slot_Pair (gib_object_t *sender, const char *signal,
|
|
|
|
gib_object_t *receiver, const char *slot);
|
|
|
|
void GIB_Object_Signal_Slot_Destroy (gib_object_t *sender, const char *signal,
|
|
|
|
gib_object_t *receiver, const char *slot);
|
|
|
|
void GIB_Object_Signal_Emit (gib_object_t *sender, int argc, const char
|
|
|
|
**argv);
|
|
|
|
void GIB_Object_Init (void);
|
2003-04-13 22:07:58 +00:00
|
|
|
|
|
|
|
// Buffer access (required to use GIB_Arg* macros)
|
|
|
|
|
|
|
|
#define GIB_DATA(buffer) ((gib_buffer_data_t *)(buffer->data))
|
|
|
|
|
|
|
|
typedef struct gib_script_s {
|
|
|
|
const char *text, *file;
|
|
|
|
unsigned int refs;
|
|
|
|
} gib_script_t;
|
|
|
|
|
|
|
|
typedef struct gib_buffer_data_s {
|
|
|
|
struct gib_script_s *script;
|
|
|
|
struct gib_tree_s *program, *ip;
|
|
|
|
struct dstring_s *arg_composite;
|
|
|
|
qboolean waitret;
|
|
|
|
struct gib_sstack_s {
|
|
|
|
struct gib_dsarray_s {
|
|
|
|
struct dstring_s **dstrs;
|
|
|
|
unsigned int realsize, size;
|
|
|
|
} *values;
|
|
|
|
unsigned int size, p;
|
|
|
|
} stack;
|
2003-09-11 06:03:13 +00:00
|
|
|
struct {
|
|
|
|
struct gib_object_s *obj;
|
|
|
|
struct gib_method_s *method;
|
|
|
|
struct gib_message_s mesg;
|
|
|
|
} reply;
|
2003-04-13 22:07:58 +00:00
|
|
|
struct hashtab_s *locals; // Local variables
|
|
|
|
struct hashtab_s *globals; // Current domain
|
2003-09-11 06:03:13 +00:00
|
|
|
void (*dnotify) (cbuf_t *cbuf, void *data);
|
|
|
|
void *ddata;
|
2003-04-13 22:07:58 +00:00
|
|
|
} gib_buffer_data_t;
|
|
|
|
|
|
|
|
// Builtin function interface
|
2002-08-03 06:04:00 +00:00
|
|
|
|
2004-01-19 07:47:41 +00:00
|
|
|
extern char * const gib_null_string;
|
2003-01-28 21:16:21 +00:00
|
|
|
|
2002-10-16 04:59:34 +00:00
|
|
|
#define GIB_Argc() (cbuf_active->args->argc)
|
2003-01-28 21:16:21 +00:00
|
|
|
#define GIB_Argv(x) ((x) < cbuf_active->args->argc ? cbuf_active->args->argv[(x)]->str : gib_null_string)
|
|
|
|
#define GIB_Args(x) ((x) < cbuf_active->args->argc ? cbuf_active->args->args[(x)] : gib_null_string)
|
2002-10-16 04:59:34 +00:00
|
|
|
#define GIB_Argd(x) ((x) < cbuf_active->args->argc ? cbuf_active->args->argv[(x)] : NULL)
|
2003-01-28 21:16:21 +00:00
|
|
|
#define GIB_Argm(x) ((x) < cbuf_active->args->argc ? (gib_tree_t *)cbuf_active->args->argm[(x)] : NULL)
|
2002-10-16 04:59:34 +00:00
|
|
|
|
2003-11-29 02:01:31 +00:00
|
|
|
#define GIB_USAGE(x) (GIB_Error ("SyntaxError", "%s: invalid syntax\nusage: %s %s", GIB_Argv(0), GIB_Argv(0), (x)))
|
2003-02-14 08:06:01 +00:00
|
|
|
|
|
|
|
#define GIB_CanReturn() (GIB_DATA(cbuf_active)->waitret)
|
2002-11-16 20:56:04 +00:00
|
|
|
|
2002-12-13 23:36:05 +00:00
|
|
|
dstring_t *GIB_Return (const char *str);
|
2003-02-14 08:06:01 +00:00
|
|
|
void GIB_Error (const char *type, const char *fmt, ...);
|
2003-04-13 22:07:58 +00:00
|
|
|
void GIB_Builtin_Add (const char *name, void (*func) (void));
|
2003-04-13 20:43:52 +00:00
|
|
|
void GIB_Builtin_Remove (const char *name);
|
|
|
|
qboolean GIB_Builtin_Exists (const char *name);
|
2003-04-13 22:07:58 +00:00
|
|
|
|
|
|
|
// Event interface
|
|
|
|
|
|
|
|
typedef struct gib_event_s {
|
|
|
|
const char *name;
|
|
|
|
struct gib_function_s *func;
|
|
|
|
} gib_event_t;
|
|
|
|
|
|
|
|
gib_event_t *GIB_Event_New (const char *name);
|
|
|
|
void GIB_Event_Callback (gib_event_t *event, unsigned int argc, ...);
|
|
|
|
|
|
|
|
// Interpreter interface (for creating GIB cbufs)
|
|
|
|
|
|
|
|
cbuf_interpreter_t *GIB_Interpreter (void);
|
|
|
|
|
|
|
|
// Thread interface
|
|
|
|
|
|
|
|
void GIB_Thread_Execute (void);
|
2003-09-11 06:03:13 +00:00
|
|
|
unsigned int GIB_Thread_Count (void);
|
2003-04-13 22:07:58 +00:00
|
|
|
|
|
|
|
// Init interface
|
|
|
|
|
|
|
|
void GIB_Init (qboolean sandbox);
|
|
|
|
|
2003-04-14 01:17:55 +00:00
|
|
|
// Handle interface
|
|
|
|
|
2003-09-11 06:03:13 +00:00
|
|
|
unsigned long int GIB_Handle_New (gib_object_t *data);
|
|
|
|
void GIB_Handle_Free (unsigned long int num);
|
|
|
|
gib_object_t *GIB_Handle_Get (unsigned long int num);
|
2003-04-13 22:07:58 +00:00
|
|
|
|
|
|
|
#endif
|