Object * Hash_delete(Object *self, Object *key) { Object *value = g_hash_table_lookup(as_hash(self)->hash, key); if (value) { g_hash_table_remove(as_hash(self)->hash, key); return value; } return nil; }
Object * Hash_keys(Object *self) { GList *keys_list = g_hash_table_get_keys(as_hash(self)->hash); Object *keys = Array_new(); while (keys_list) { Array_push(keys, as_object(keys_list->data)); keys_list = keys_list->next; } return keys; }
Object * Hash__INDEX__EQ_(Object *self, Object *key, Object *value) { g_hash_table_insert(as_hash(self)->hash, key, value); return value; }
Object * Hash__INDEX_(Object *self, Object *key) { Object *value = g_hash_table_lookup(as_hash(self)->hash, key); return value ? value : nil; }
void Hash__INIT(Object* x) { as_hash(x)->hash = g_hash_table_new(hash_func, equal_func); }
const char* list_as_string( BehaviorTreeContext tree, Parameter* v ) { const char* ret = ""; int space = 0; int written = 0; char* str = 0x0; char* s; while( v ) { char tmp[1024]; int n = sprintf( tmp, "%s = ", v->m_Id.m_Text ); if( space - (n + written + 1) < 0 ) { space = max( space * 2, n + written + 1 ); str = (char*)realloc( str, space ); } s = str + written; memcpy( s, tmp, n + 1 ); written += n; switch( v->m_Type ) { case E_VART_INTEGER: n = sprintf( tmp, "%d", as_integer( *v ) ); break; case E_VART_FLOAT: n = sprintf( tmp, "%f", as_float( *v ) ); break; case E_VART_STRING: n = sprintf( tmp, "\"%s\"", as_string( *v )->m_Parsed ); break; case E_VART_BOOL: n = sprintf( tmp, "%s", as_bool( *v ) ? "true" : "false" ); break; case E_VART_HASH: n = sprintf( tmp, "0x%08x", as_hash( *v ) ); break; case E_VART_UNDEFINED: case E_MAX_VARIABLE_TYPE: break; } v = v->m_Next; if( v ) { tmp[++n] = ','; tmp[++n] = ' '; tmp[n + 1] = 0; } if( space - (n + written + 1) < 0 ) { space = max( space * 2, n + written + 1 ); str = (char*)realloc( str, space ); } s = str + written; memcpy( s, tmp, n + 1 ); written += n; } if( str ) { if( tree ) ret = register_string( tree, str ); free( str ); str = 0x0; } return ret; }