|
|
| version 1.35, 2015/10/25 22:24:05 | version 1.40, 2016/03/31 21:46:20 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: @b reflection parser class. | Parser: @b reflection parser class. |
| Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com) | Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| */ | */ |
| Line 37 public: | Line 37 public: |
| // global variable | // global variable |
| DECLARE_CLASS_VAR(reflection, new MReflection, 0); | DECLARE_CLASS_VAR(reflection, new MReflection); |
| // methods | // methods |
| Line 334 static void _dynamical(Request& r, Metho | Line 334 static void _dynamical(Request& r, Metho |
| } | } |
| static void _is(Request& r, MethodParams& params) { | static void _is(Request& r, MethodParams& params) { |
| const String& type=params.as_string(0, "class name must be string"); | const String& name=params.as_string(0, "element name must be string"); |
| const String& name=params.as_string(params.count()-1, "element name must be string"); | const String& type=params.as_string(1, "class name must be string"); |
| Value &context=params.count()==3 ? params.as_no_junction(1, "context must not be code") : *(r.get_method_frame()->caller()); | Value *context=params.count()==3 ? &(params.as_no_junction(2, "context must not be code")) : r.get_method_frame()->caller(); |
| Value *value=context.get_element(name); | Value *value=context ? context->get_element(name) : 0; |
| if(value) { | if(value) { |
| if(type == "code" || type == "method") { | if(type == "code" || type == "method") { |
| Line 347 static void _is(Request& r, MethodParams | Line 347 static void _is(Request& r, MethodParams |
| r.write_no_lang(VBool::get( value->is(type.cstr()) )); | r.write_no_lang(VBool::get( value->is(type.cstr()) )); |
| } | } |
| } else | } else |
| r.write_no_lang(VBool::get(false)); | r.write_no_lang(VBool::get(type == "void")); |
| } | } |
| static void _copy(Request& r, MethodParams& params) { | static void _copy(Request& r, MethodParams& params) { |
| Line 423 MReflection::MReflection(): Methoded("re | Line 423 MReflection::MReflection(): Methoded("re |
| // ^reflection:dynamical[[object or class, caller if absent]] | // ^reflection:dynamical[[object or class, caller if absent]] |
| add_native_method("dynamical", Method::CT_STATIC, _dynamical, 0, 1); | add_native_method("dynamical", Method::CT_STATIC, _dynamical, 0, 1); |
| // ^reflection:is[class_name|code|method;[context;]element_name] | // ^reflection:is[element_name;class_name|code|method[;context]] |
| add_native_method("is", Method::CT_STATIC, _is, 2, 3); | add_native_method("is", Method::CT_STATIC, _is, 2, 3); |
| // ^reflection:copy[src;dst] | // ^reflection:copy[src;dst] |