#include #include #include #include struct bshell_variable_p { char *var_name; fx_value var_value; }; static void variable_fini(fx_object *obj, void *priv) { struct bshell_variable_p *block = priv; if (block->var_name) { free(block->var_name); } fx_value_unset(&block->var_value); } static const char *variable_get_name(struct bshell_variable_p *var) { return var->var_name; } static const fx_value *variable_get_value(const struct bshell_variable_p *var) { return &var->var_value; } static void variable_set_value(struct bshell_variable_p *var, fx_value value) { fx_value_unset(&var->var_value); var->var_value = fx_value_copy_return(value); } bshell_variable *bshell_variable_create(const char *name) { bshell_variable *var = fx_object_create(BSHELL_TYPE_VARIABLE); if (!var) { return NULL; } struct bshell_variable_p *p = fx_object_get_private(var, BSHELL_TYPE_VARIABLE); p->var_name = fx_strdup(name); if (!p->var_name) { bshell_variable_unref(var); return NULL; } return var; } const char *bshell_variable_get_name(const bshell_variable *var) { FX_CLASS_DISPATCH_STATIC_0( BSHELL_TYPE_VARIABLE, variable_get_name, var); } const fx_value *bshell_variable_get_value(const bshell_variable *var) { FX_CLASS_DISPATCH_STATIC_0( BSHELL_TYPE_VARIABLE, variable_get_value, var); } void bshell_variable_set_value(bshell_variable *var, fx_value value) { FX_CLASS_DISPATCH_STATIC_V( BSHELL_TYPE_VARIABLE, variable_set_value, var, value); } FX_TYPE_CLASS_BEGIN(bshell_variable) FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT) FX_INTERFACE_ENTRY(to_string) = NULL; FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT) FX_TYPE_CONSTRUCTOR("create", bshell_variable_create, 1, FX_TYPE_CSTR); FX_TYPE_CLASS_END(bshell_variable) FX_TYPE_DEFINITION_BEGIN(bshell_variable) FX_TYPE_ID(0x4e93b9d9, 0x2c11, 0x4fd7, 0xa9ce, 0x41b7cd20f0d4); FX_TYPE_NAME("bshell.variable"); FX_TYPE_CLASS(bshell_variable_class); FX_TYPE_INSTANCE_PRIVATE(struct bshell_variable_p); FX_TYPE_INSTANCE_FINI(variable_fini); FX_TYPE_DEFINITION_END(bshell_variable)