--- parser3/src/classes/reflection.C 2016/05/24 15:42:43 1.42 +++ parser3/src/classes/reflection.C 2016/07/20 14:51:16 1.45 @@ -9,7 +9,7 @@ #include "pa_request.h" #include "pa_vbool.h" -volatile const char * IDENT_REFLECTION_C="$Id: reflection.C,v 1.42 2016/05/24 15:42:43 moko Exp $"; +volatile const char * IDENT_REFLECTION_C="$Id: reflection.C,v 1.45 2016/07/20 14:51:16 moko Exp $"; static const String class_type_methoded("methoded"); @@ -193,7 +193,7 @@ static void _def(Request& r, MethodParam const String& type=params.as_string(0, "type must be string"); if(type == def_class) { const String& name=params.as_string(1, "name must be string"); - r.write_no_lang(VBool::get(r.get_class(name)!=0)); + r.write_no_lang(VBool::get(r.classes().get(name)!=0)); } else { throw Exception(PARSER_RUNTIME, &type, "is invalid type, must be '%s'", def_class.cstr()); } @@ -232,13 +232,21 @@ static void _method(Request& r, MethodPa static void _fields(Request& r, MethodParams& params) { Value& o=params.as_no_junction(0, "param must be object or class, not junction"); - if(HashStringValue* fields=o.get_fields()) { - VHash& result=*new VHash(*fields); - r.write_no_lang(result); - } else + if(HashStringValue* fields=o.get_fields()) + r.write_no_lang(*new VHash(*fields)); + else r.write_no_lang(*new VHash()); } +static void _fields_reference(Request& r, MethodParams& params) { + Value& o=params.as_no_junction(0, "param must be object or class, not junction"); + + if(HashStringValue* fields=o.get_fields_reference()) + r.write_no_lang(*new VHashReference(*fields)); + else + throw Exception(PARSER_RUNTIME, 0, "param must be object or class"); +} + static void _field(Request& r, MethodParams& params) { Value& o=params.as_no_junction(0, "first param must be object or class, not junction"); const String& name=params.as_string(1, "field name must be string"); @@ -252,23 +260,16 @@ static void _method_info(Request& r, Met const String& class_name=params.as_string(0, "class_name must be string"); Value* class_value=r.get_class(class_name); if(!class_value) - throw Exception(PARSER_RUNTIME, - &class_name, - "class is undefined"); + throw Exception(PARSER_RUNTIME, &class_name, "class is undefined"); VStateless_class* lclass=class_value->get_class(); if(!lclass) - throw Exception(PARSER_RUNTIME, - &class_name, - "class does not have methods"); + throw Exception(PARSER_RUNTIME, &class_name, "class does not have methods"); const String& method_name=params.as_string(1, "method_name must be string"); Method* method=lclass->get_method(method_name); if(!method) - throw Exception(PARSER_RUNTIME, - &method_name, - "method not found in class %s", - class_name.cstr()); + throw Exception(PARSER_RUNTIME, &method_name, "method not found in class %s", class_name.cstr()); VHash& result=*new VHash; HashStringValue* hash=result.get_hash(); @@ -348,7 +349,7 @@ static void _is(Request& r, MethodParams static void _copy(Request& r, MethodParams& params) { HashStringValue* src=params.as_no_junction(0, "source must not be code").get_hash(); - if(src==NULL) + if(src==NULL) throw Exception(PARSER_RUNTIME, 0, "source must have hash representation"); Value& dst=params.as_no_junction(1, "destination must not be code"); @@ -412,6 +413,9 @@ MReflection::MReflection(): Methoded("re // ^reflection:fields[object or class] add_native_method("fields", Method::CT_STATIC, _fields, 1, 1); + // ^reflection:fields_reference[object] + add_native_method("fields_reference", Method::CT_STATIC, _fields_reference, 1, 1); + // ^reflection:field[object or class;field_name] add_native_method("field", Method::CT_STATIC, _field, 2, 2);