instanceMemberGet method

  1. @override
dynamic instanceMemberGet(
  1. dynamic object,
  2. String varName
)
override

Default HTExternalClass constructor. Fetch a instance member of the Dart class by the varName, in the form of

object.key

Implementation

@override
dynamic instanceMemberGet(dynamic object, String varName) {
  final hetu = object as Hetu;
  switch (varName) {
    case 'stringify':
      return (HTEntity entity,
              {List<dynamic> positionalArgs = const [],
              Map<String, dynamic> namedArgs = const {},
              List<HTType> typeArgs = const []}) =>
          hetu.lexicon.stringify(positionalArgs.first);
    case 'createStructfromJson':
      return (HTEntity entity,
          {List<dynamic> positionalArgs = const [],
          Map<String, dynamic> namedArgs = const {},
          List<HTType> typeArgs = const []}) {
        final jsonData = positionalArgs.first as Map<dynamic, dynamic>;
        return hetu.interpreter.createStructfromJson(jsonData);
      };
    case 'jsonify':
      return (HTEntity entity,
          {List<dynamic> positionalArgs = const [],
          Map<String, dynamic> namedArgs = const {},
          List<HTType> typeArgs = const []}) {
        final object = positionalArgs.first;
        if (object is HTStruct) {
          return jsonifyStruct(object);
        } else if (object is Iterable) {
          return jsonifyList(object);
        } else if (isJsonDataType(object)) {
          return hetu.lexicon.stringify(object);
        } else {
          return jsonEncode(object);
        }
      };
    case 'eval':
      return (HTEntity entity,
          {List<dynamic> positionalArgs = const [],
          Map<String, dynamic> namedArgs = const {},
          List<HTType> typeArgs = const []}) {
        final code = positionalArgs.first as String;
        final HTContext storedContext = hetu.interpreter.getContext();
        final result = hetu.eval(code);
        hetu.interpreter.setContext(context: storedContext);
        return result;
      };
    case 'require':
      return (HTEntity entity,
              {List<dynamic> positionalArgs = const [],
              Map<String, dynamic> namedArgs = const {},
              List<HTType> typeArgs = const []}) =>
          hetu.require(positionalArgs.first);
    case 'help':
      return (HTEntity entity,
              {List<dynamic> positionalArgs = const [],
              Map<String, dynamic> namedArgs = const {},
              List<HTType> typeArgs = const []}) =>
          hetu.help(positionalArgs.first);
    default:
      throw HTError.undefined(varName);
  }
}