{"action":"opened","issue":{"url":"https://api.github.com/repos/tsoding/nothing/issues/608","repository_url":"https://api.github.com/repos/tsoding/nothing","labels_url":"https://api.github.com/repos/tsoding/nothing/issues/608/labels{/name}","comments_url":"https://api.github.com/repos/tsoding/nothing/issues/608/comments","events_url":"https://api.github.com/repos/tsoding/nothing/issues/608/events","html_url":"https://github.com/tsoding/nothing/issues/608","id":394906663,"node_id":"MDU6SXNzdWUzOTQ5MDY2NjM=","number":608,"title":"Reflector","user":{"login":"rexim","id":165283,"node_id":"MDQ6VXNlcjE2NTI4Mw==","avatar_url":"https://avatars3.githubusercontent.com/u/165283?v=4","gravatar_id":"","url":"https://api.github.com/users/rexim","html_url":"https://github.com/rexim","followers_url":"https://api.github.com/users/rexim/followers","following_url":"https://api.github.com/users/rexim/following{/other_user}","gists_url":"https://api.github.com/users/rexim/gists{/gist_id}","starred_url":"https://api.github.com/users/rexim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rexim/subscriptions","organizations_url":"https://api.github.com/users/rexim/orgs","repos_url":"https://api.github.com/users/rexim/repos","events_url":"https://api.github.com/users/rexim/events{/privacy}","received_events_url":"https://api.github.com/users/rexim/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-12-30T22:37:14Z","updated_at":"2018-12-30T22:37:14Z","closed_at":null,"author_association":"MEMBER","body":"### Definition\r\n\r\n```c\r\nstruct Reflector {\r\n    Game *game;\r\n};\r\n\r\nstruct EvalResult unknown_object(Gc *gc, const char *source, const char *target)\r\n{\r\n    return list(gc, \"qqq\", \"unknown-object\", source, target);\r\n}\r\n\r\nstruct EvalResult reflector_send(Reflector *reflector,\r\n                                 Gc *gc,\r\n                                 struct Scope *scope,\r\n                                 struct Expr path)\r\n{\r\n    const char *target = NULL;\r\n    struct Expr rest = NIL(gc);\r\n    struct EvalResult res = match_list(gc, \"q*\", path, &target, &rest);\r\n    if (res.is_error) {\r\n        return res;\r\n    }\r\n\r\n    if (strcmp(target, \"game\") == 0) {\r\n        return game_send(reflector->game, gc, scope, rest);\r\n    } else {\r\n        return unknown_object(gc, \"root\", target);\r\n    }\r\n}\r\n```\r\n\r\n### game_send\r\n\r\n```c\r\n  struct EvalResult game_send(Game *game, Gc *gc, struct Scope *scope, struct Expr path)\r\n  {\r\n      const char *target = NULL;\r\n      struct Expr rest = NIL(gc);\r\n      struct EvalResult res = match_list(gc, \"q*\", path, &target, &rest);\r\n      if (res.is_error) {\r\n          return res;\r\n      }\r\n\r\n      switch (0) {\r\n      case strcmp(target, \"level\"):\r\n          return level_send(game->level, gc, scope, rest);\r\n\r\n      case strcmp(target, \"camera\"):\r\n          return camera_send(game->camera, gc, scope, rest);\r\n\r\n          ...\r\n      }\r\n  }\r\n```\r\n\r\n  Etc. down to the leaves of the Game Tree.\r\n\r\n### Sending messages\r\n\r\n```lisp\r\n  (send '(game level goal \"goal-1\" hide))\r\n  (send '(game level goal \"goal-2\" show))\r\n  (send '(game level player alive-body apply-force (0 -50000)))\r\n  (send '(game level boxes \"box-1-2\" apply-force (0 -50000)))\r\n```\r\n\r\n### Receiving Data\r\n\r\n```lisp\r\n  (when (> (send '(game level player jump-count)) 2)\r\n    (send '(game level labels \"jump\" hide)))\r\n```\r\n"}}
{"actor":{"display_login":"rexim"}}