summaryrefslogtreecommitdiff
path: root/src/map/script.h
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2013-06-08 18:48:33 -0300
committershennetsind <ind@henn.et>2013-06-08 18:48:33 -0300
commit33694ca1d002c2474d4b1aeb964524249b726064 (patch)
tree0d84cbe52d070277c989388b07a9e0ac46e7f907 /src/map/script.h
parent1f983da55f7ee40da651bb84bab518ddc7312dbc (diff)
downloadhercules-33694ca1d002c2474d4b1aeb964524249b726064.tar.gz
hercules-33694ca1d002c2474d4b1aeb964524249b726064.tar.bz2
hercules-33694ca1d002c2474d4b1aeb964524249b726064.tar.xz
hercules-33694ca1d002c2474d4b1aeb964524249b726064.zip
HPM: Update script.c
Further implemented the interface Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/map/script.h')
-rw-r--r--src/map/script.h66
1 files changed, 46 insertions, 20 deletions
diff --git a/src/map/script.h b/src/map/script.h
index 2e8dde5cf..ab4a58626 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -214,6 +214,24 @@ int script_reload(void);
// @commands (script based)
void setd_sub(struct script_state *st, struct map_session_data *sd, const char *varname, int elem, void *value, struct DBMap **ref);
+struct script_function {
+ bool (*func)(struct script_state *st);
+ char *name;
+ char *arg;
+};
+
+// String buffer structures.
+// str_data stores string information
+struct str_data_struct {
+ enum c_op type;
+ int str;
+ int backpatch;
+ int label;
+ bool (*func)(struct script_state *st);
+ int val;
+ int next;
+};
+
///////////////////////////////////////////////////////////////////////////////
//## TODO possible enhancements: [FlavioJS]
// - 'callfunc' supporting labels in the current npc "::LabelName"
@@ -237,17 +255,17 @@ void setd_sub(struct script_state *st, struct map_session_data *sd, const char *
/// Returns the index of the last data in the stack
#define script_lastdata(st) ( (st)->end - (st)->start - 1 )
/// Pushes an int into the stack
-#define script_pushint(st,val) push_val((st)->stack, C_INT, (val))
+#define script_pushint(st,val) script->push_val((st)->stack, C_INT, (val),NULL)
/// Pushes a string into the stack (script engine frees it automatically)
-#define script_pushstr(st,val) push_str((st)->stack, C_STR, (val))
+#define script_pushstr(st,val) script->push_str((st)->stack, C_STR, (val))
/// Pushes a copy of a string into the stack
-#define script_pushstrcopy(st,val) push_str((st)->stack, C_STR, aStrdup(val))
+#define script_pushstrcopy(st,val) script->push_str((st)->stack, C_STR, aStrdup(val))
/// Pushes a constant string into the stack (must never change or be freed)
-#define script_pushconststr(st,val) push_str((st)->stack, C_CONSTSTR, (val))
+#define script_pushconststr(st,val) script->push_str((st)->stack, C_CONSTSTR, (val))
/// Pushes a nil into the stack
-#define script_pushnil(st) push_val((st)->stack, C_NOP, 0)
+#define script_pushnil(st) script->push_val((st)->stack, C_NOP, 0,NULL)
/// Pushes a copy of the data in the target index
-#define script_pushcopy(st,i) push_copy((st)->stack, (st)->start + (i))
+#define script_pushcopy(st,i) script->push_copy((st)->stack, (st)->start + (i))
#define script_isstring(st,i) data_isstring(script_getdata(st,i))
#define script_isint(st,i) data_isint(script_getdata(st,i))
@@ -262,9 +280,9 @@ void setd_sub(struct script_state *st, struct map_session_data *sd, const char *
/// Returns the script_data at the target index relative to the top of the stack
#define script_getdatatop(st,i) ( &((st)->stack->stack_data[(st)->stack->sp + (i)]) )
/// Pushes a copy of the data in the target index relative to the top of the stack
-#define script_pushcopytop(st,i) push_copy((st)->stack, (st)->stack->sp + (i))
+#define script_pushcopytop(st,i) script->push_copy((st)->stack, (st)->stack->sp + (i))
/// Removes the range of values [start,end[ relative to the top of the stack
-#define script_removetop(st,start,end) ( pop_stack((st), ((st)->stack->sp + (start)), (st)->stack->sp + (end)) )
+#define script_removetop(st,start,end) ( script->pop_stack((st), ((st)->stack->sp + (start)), (st)->stack->sp + (end)) )
//
// struct script_data* data;
@@ -282,12 +300,12 @@ void setd_sub(struct script_state *st, struct map_session_data *sd, const char *
#define data_isfunclabel(data) ( (data)->type == C_USERFUNC_POS )
/// Returns if this is a reference to a constant
-#define reference_toconstant(data) ( str_data[reference_getid(data)].type == C_INT )
+#define reference_toconstant(data) ( script->str_data[reference_getid(data)].type == C_INT )
/// Returns if this a reference to a param
-#define reference_toparam(data) ( str_data[reference_getid(data)].type == C_PARAM )
+#define reference_toparam(data) ( script->str_data[reference_getid(data)].type == C_PARAM )
/// Returns if this a reference to a variable
//##TODO confirm it's C_NAME [FlavioJS]
-#define reference_tovariable(data) ( str_data[reference_getid(data)].type == C_NAME )
+#define reference_tovariable(data) ( script->str_data[reference_getid(data)].type == C_NAME )
/// Returns the unique id of the reference (id and index)
#define reference_getuid(data) ( (data)->u.num )
/// Returns the id of the reference
@@ -295,13 +313,13 @@ void setd_sub(struct script_state *st, struct map_session_data *sd, const char *
/// Returns the array index of the reference
#define reference_getindex(data) ( (int32)(((uint32)(reference_getuid(data) & 0xff000000)) >> 24) )
/// Returns the name of the reference
-#define reference_getname(data) ( str_buf + str_data[reference_getid(data)].str )
+#define reference_getname(data) ( script->str_buf + script->str_data[reference_getid(data)].str )
/// Returns the linked list of uid-value pairs of the reference (can be NULL)
#define reference_getref(data) ( (data)->ref )
/// Returns the value of the constant
-#define reference_getconstant(data) ( str_data[reference_getid(data)].val )
+#define reference_getconstant(data) ( script->str_data[reference_getid(data)].val )
/// Returns the type of param
-#define reference_getparamtype(data) ( str_data[reference_getid(data)].val )
+#define reference_getparamtype(data) ( script->str_data[reference_getid(data)].val )
/// Composes the uid of a reference from the id and the index
#define reference_uid(id,idx) ( (int32)((((uint32)(id)) & 0x00ffffff) | (((uint32)(idx)) << 24)) )
@@ -313,12 +331,6 @@ void setd_sub(struct script_state *st, struct map_session_data *sd, const char *
#define BUILDIN(x) bool buildin_ ## x (struct script_state* st)
#define BUILDIN_A(x) buildin_ ## x
-struct script_function {
- bool (*func)(struct script_state *st);
- char *name;
- char *arg;
-};
-
/* script.c interface (incomplete) */
struct script_interface {
/* */
@@ -329,6 +341,14 @@ struct script_interface {
/* */
char **buildin;
unsigned int buildin_count;
+ /* */
+ struct str_data_struct *str_data;
+ int str_data_size; // size of the data
+ int str_num; // next id to be assigned
+ // str_buf holds the strings themselves
+ char *str_buf;
+ int str_size; // size of the buffer
+ int str_pos; // next position to be assigned
/* */
void (*init) (void);
void (*final) (void);
@@ -338,6 +358,12 @@ struct script_interface {
int (*conv_num) (struct script_state *st,struct script_data *data);
const char* (*conv_str) (struct script_state *st,struct script_data *data);
TBL_PC *(*rid2sd) (struct script_state *st);
+ struct script_data* (*push_val)(struct script_stack* stack, enum c_op type, int val, struct DBMap** ref);
+ void (*get_val) (struct script_state* st, struct script_data* data);
+ void* (*get_val2) (struct script_state* st, int uid, struct DBMap** ref);
+ struct script_data* (*push_str) (struct script_stack* stack, enum c_op type, char* str);
+ struct script_data* (*push_copy) (struct script_stack* stack, int pos);
+ void (*pop_stack) (struct script_state* st, int start, int end);
/* */
struct hQueue *(*queue) (int idx);
bool (*queue_add) (int idx, int var);