char *name = exp->data.string;
script_obj_t *obj = script_obj_hash_peek_element (state->local, name);
if (obj) return obj;
+ obj = script_obj_hash_peek_element (state->this, name);
+ if (obj) return obj;
obj = script_obj_hash_peek_element (state->global, name);
if (obj) return obj;
obj = script_obj_hash_get_element (state->local, name);
return state->global;
}
+ case SCRIPT_EXP_TYPE_TERM_THIS:
+ {
+ script_obj_ref (state->this);
+ return state->this;
+ }
+
case SCRIPT_EXP_TYPE_TERM_VAR:
{
return script_evaluate_var (state, exp);
script_obj_t *this,
ply_list_t *parameter_data)
{
- script_state_t *sub_state = script_state_init_sub (state);
+ script_state_t *sub_state = script_state_init_sub (state, this);
ply_list_t *parameter_names = function->parameters;
ply_list_node_t *node_name = ply_list_get_first_node (parameter_names);
ply_list_node_t *node_data = ply_list_get_first_node (parameter_data);
const char *name)
{
hash = script_obj_deref_direct (hash);
- assert (hash->type == SCRIPT_OBJ_TYPE_HASH);
+ if (hash->type != SCRIPT_OBJ_TYPE_HASH) return NULL;
script_variable_t *variable = ply_hashtable_lookup (hash->data.hash,
(void *) name);
if (!variable) return NULL;
script_obj_t *element,
const char *name)
{
- assert (hash->type == SCRIPT_OBJ_TYPE_HASH);
script_obj_t *obj = script_obj_hash_get_element (hash, name);
script_obj_assign (obj, element);
script_obj_unref (obj);
}
static const script_parse_operator_table_entry_t* /* Only allows 1 or 2 character symbols */
-script_parse_operator_table_entry_lookup (script_scan_t *scan,
+script_parse_operator_table_entry_lookup (script_scan_t *scan,
const script_parse_operator_table_entry_t *table)
{
int entry_index;
exp = script_parse_new_exp(SCRIPT_EXP_TYPE_TERM_GLOBAL, &curtoken->location);
else if (script_scan_token_is_identifier_of_value (curtoken, "local"))
exp = script_parse_new_exp(SCRIPT_EXP_TYPE_TERM_LOCAL, &curtoken->location);
+ else if (script_scan_token_is_identifier_of_value (curtoken, "this"))
+ exp = script_parse_new_exp(SCRIPT_EXP_TYPE_TERM_THIS, &curtoken->location);
else if (script_scan_token_is_identifier_of_value (curtoken, "fun"))
{
script_debug_location_t location = curtoken->location;
case SCRIPT_EXP_TYPE_TERM_NULL:
case SCRIPT_EXP_TYPE_TERM_LOCAL:
case SCRIPT_EXP_TYPE_TERM_GLOBAL:
+ case SCRIPT_EXP_TYPE_TERM_THIS:
break;
case SCRIPT_EXP_TYPE_FUNCTION_EXE:
#include "script-parse.h"
#include "script-object.h"
-script_function_t *script_function_script_new (script_op_t *script,
- void *user_data,
- ply_list_t *parameter_list)
+script_function_t *script_function_script_new (script_op_t *script,
+ void *user_data,
+ ply_list_t *parameter_list)
{
script_function_t *function = malloc (sizeof (script_function_t));
return function;
}
-script_function_t *script_function_native_new (script_native_function_t native_function,
- void *user_data,
- ply_list_t *parameter_list)
+script_function_t *script_function_native_new (script_native_function_t native_function,
+ void *user_data,
+ ply_list_t *parameter_list)
{
script_function_t *function = malloc (sizeof (script_function_t));
script_state_t *script_state_new (void *user_data)
{
script_state_t *state = malloc (sizeof (script_state_t));
-
- state->global = script_obj_new_hash ();
- script_obj_ref (state->global);
- state->local = state->global;
+ script_obj_t *global_hash = script_obj_new_hash ();
+ state->global = script_obj_new_ref (global_hash);
+ script_obj_unref(global_hash);
+ state->local = script_obj_new_ref (global_hash);
+ state->this = script_obj_new_null();
state->user_data = user_data;
return state;
}
-script_state_t *script_state_init_sub (script_state_t *oldstate)
+script_state_t *script_state_init_sub (script_state_t *oldstate, script_obj_t *this)
{
script_state_t *newstate = malloc (sizeof (script_state_t));
-
- newstate->global = oldstate->global;
- script_obj_ref (newstate->global);
- newstate->local = script_obj_new_hash ();
+ script_obj_t *local_hash = script_obj_new_hash ();
+ newstate->local = script_obj_new_ref (local_hash);
+ script_obj_unref(local_hash);
+ newstate->global = script_obj_new_ref (oldstate->global);
+ if (this) newstate->this = script_obj_new_ref (this);
+ else newstate->this = script_obj_new_ref (oldstate->this);
newstate->user_data = oldstate->user_data;
return newstate;
}
{
script_obj_unref (state->global);
script_obj_unref (state->local);
+ script_obj_unref (state->this);
free (state);
}
void *user_data;
struct script_obj_t *global;
struct script_obj_t *local;
+ struct script_obj_t *this;
} script_state_t;
typedef enum
SCRIPT_EXP_TYPE_TERM_VAR,
SCRIPT_EXP_TYPE_TERM_LOCAL,
SCRIPT_EXP_TYPE_TERM_GLOBAL,
+ SCRIPT_EXP_TYPE_TERM_THIS,
SCRIPT_EXP_TYPE_PLUS,
SCRIPT_EXP_TYPE_MINUS,
SCRIPT_EXP_TYPE_MUL,
void script_obj_native_class_destroy (script_obj_native_class_t * class);
script_state_t *script_state_new (void *user_data);
-script_state_t *script_state_init_sub (script_state_t *oldstate);
+script_state_t *script_state_init_sub (script_state_t *oldstate, script_obj_t *this);
void script_state_destroy (script_state_t *state);
#endif /* SCRIPT_H */