{"action":"created","issue":{"url":"https://api.github.com/repos/munificent/wren/issues/498","repository_url":"https://api.github.com/repos/munificent/wren","labels_url":"https://api.github.com/repos/munificent/wren/issues/498/labels{/name}","comments_url":"https://api.github.com/repos/munificent/wren/issues/498/comments","events_url":"https://api.github.com/repos/munificent/wren/issues/498/events","html_url":"https://github.com/munificent/wren/issues/498","id":284800410,"number":498,"title":"How to validate arguments for foreign methods from native code?","user":{"login":"heretique","id":139596,"avatar_url":"https://avatars0.githubusercontent.com/u/139596?v=4","gravatar_id":"","url":"https://api.github.com/users/heretique","html_url":"https://github.com/heretique","followers_url":"https://api.github.com/users/heretique/followers","following_url":"https://api.github.com/users/heretique/following{/other_user}","gists_url":"https://api.github.com/users/heretique/gists{/gist_id}","starred_url":"https://api.github.com/users/heretique/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heretique/subscriptions","organizations_url":"https://api.github.com/users/heretique/orgs","repos_url":"https://api.github.com/users/heretique/repos","events_url":"https://api.github.com/users/heretique/events{/privacy}","received_events_url":"https://api.github.com/users/heretique/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":16,"created_at":"2017-12-27T21:38:09Z","updated_at":"2018-03-27T17:43:11Z","closed_at":null,"author_association":"NONE","body":"Hi,\r\n\r\nI was wondering if it is possible to validate arguments for foreign methods from within the native foreign method. From [this](https://groups.google.com/forum/#!searchin/wren-lang/foreign$20method$20wrong$20arguments%7Csort:date/wren-lang/9QIiHrNFsxQ/GDJOWPjHBgAJ) thread I've seen that one way of doing it is to have the checks from wren using the \"is\" keyword to makes sure the arguments is of the expected type. But this approach means creating a lot of wrapper methods over the actual foreign ones (polluting the script and they cannot be private as far as I know). For example if I have a **Vec3** class:\r\n\r\n```\r\nforeign class Vec3 {\r\n    construct new( x, y, z ) {}\r\n    foreign *( rhs )\r\n    foreign +( rhs )\r\n    foreign -( rhs ) \r\n} \r\n```\r\nI would like to make sure \"**rhs**\" is a **Vec3** before I cast it to the native vector class in the foreign operator implementation. I could check that the slot for the argument contains a foreign type but can't say for sure it's a Vec3 or Vec2 and I could have a lot of problems casting to the wrong type. Does this make sense?\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/munificent/wren/issues/comments/376612973","html_url":"https://github.com/munificent/wren/issues/498#issuecomment-376612973","issue_url":"https://api.github.com/repos/munificent/wren/issues/498","id":376612973,"user":{"login":"munificent","id":46275,"avatar_url":"https://avatars0.githubusercontent.com/u/46275?v=4","gravatar_id":"","url":"https://api.github.com/users/munificent","html_url":"https://github.com/munificent","followers_url":"https://api.github.com/users/munificent/followers","following_url":"https://api.github.com/users/munificent/following{/other_user}","gists_url":"https://api.github.com/users/munificent/gists{/gist_id}","starred_url":"https://api.github.com/users/munificent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/munificent/subscriptions","organizations_url":"https://api.github.com/users/munificent/orgs","repos_url":"https://api.github.com/users/munificent/repos","events_url":"https://api.github.com/users/munificent/events{/privacy}","received_events_url":"https://api.github.com/users/munificent/received_events","type":"User","site_admin":false},"created_at":"2018-03-27T17:43:11Z","updated_at":"2018-03-27T17:43:11Z","author_association":"OWNER","body":"> Just curious, but why couldn't you simply compare the ObjClass pointers rather than going through an ID?\r\n\r\nThe pointers aren't exposed to the C API and we don't want to expose raw pointers because doing so would prevent us from ever supporting a moving/copying GC in the future. (That's also why WrenHandle exists, more or less.)\r\n\r\nWe could do something like:\r\n\r\n```c\r\nbool wrenIsClass(WrenVM* vm, int slot, WrenHandle classHandle);\r\n```\r\n\r\nThat would return `true` if the class of the object in [slot] is the same as the class stored in `classHandle`.\r\n"}}
{"actor":{"display_login":"munificent"}}