{"action":"created","issue":{"url":"https://api.github.com/repos/svaarala/duktape/issues/468","labels_url":"https://api.github.com/repos/svaarala/duktape/issues/468/labels{/name}","comments_url":"https://api.github.com/repos/svaarala/duktape/issues/468/comments","events_url":"https://api.github.com/repos/svaarala/duktape/issues/468/events","html_url":"https://github.com/svaarala/duktape/issues/468","id":119340232,"number":468,"title":"How get function passed as argument in an native function ?","user":{"login":"leonardosnt","id":13869336,"avatar_url":"https://avatars.githubusercontent.com/u/13869336?v=3","gravatar_id":"","url":"https://api.github.com/users/leonardosnt","html_url":"https://github.com/leonardosnt","followers_url":"https://api.github.com/users/leonardosnt/followers","following_url":"https://api.github.com/users/leonardosnt/following{/other_user}","gists_url":"https://api.github.com/users/leonardosnt/gists{/gist_id}","starred_url":"https://api.github.com/users/leonardosnt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leonardosnt/subscriptions","organizations_url":"https://api.github.com/users/leonardosnt/orgs","repos_url":"https://api.github.com/users/leonardosnt/repos","events_url":"https://api.github.com/users/leonardosnt/events{/privacy}","received_events_url":"https://api.github.com/users/leonardosnt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-11-29T06:05:30Z","updated_at":"2015-11-29T12:25:03Z","closed_at":null,"body":"cpp:\r\n```cpp\r\nint bind( duk_context *ctx )\r\n{\r\n\tif ( !duk_is_function(ctx, 0) )\r\n\t{\r\n\t\t// throw\r\n\t}\r\n\r\n\t// save the function to call later\r\n\treturn 1;\r\n}\r\n```\r\n\r\njs:\r\n```javascript\r\nbind(function () { print (\"hello\") });\r\n```"},"comment":{"url":"https://api.github.com/repos/svaarala/duktape/issues/comments/160413322","html_url":"https://github.com/svaarala/duktape/issues/468#issuecomment-160413322","issue_url":"https://api.github.com/repos/svaarala/duktape/issues/468","id":160413322,"user":{"login":"svaarala","id":6377415,"avatar_url":"https://avatars.githubusercontent.com/u/6377415?v=3","gravatar_id":"","url":"https://api.github.com/users/svaarala","html_url":"https://github.com/svaarala","followers_url":"https://api.github.com/users/svaarala/followers","following_url":"https://api.github.com/users/svaarala/following{/other_user}","gists_url":"https://api.github.com/users/svaarala/gists{/gist_id}","starred_url":"https://api.github.com/users/svaarala/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/svaarala/subscriptions","organizations_url":"https://api.github.com/users/svaarala/orgs","repos_url":"https://api.github.com/users/svaarala/repos","events_url":"https://api.github.com/users/svaarala/events{/privacy}","received_events_url":"https://api.github.com/users/svaarala/received_events","type":"User","site_admin":false},"created_at":"2015-11-29T12:25:03Z","updated_at":"2015-11-29T12:25:03Z","body":"Yes, you can then just do the equivalent in C:\r\n\r\n```\r\nint bind( duk_context *ctx )\r\n{\r\n    if ( !duk_is_function(ctx, 0) )\r\n    {\r\n        duk_error(ctx, DUK_ERR_TYPE_ERROR, \"not a function\");\r\n    }\r\n\r\n    duk_put_global_string(ctx, \"storedFunc\");\r\n    return 0;\r\n}\r\n\r\nint call( duk_context *ctx )\r\n{\r\n    duk_get_global_string(ctx, \"storedFunc\");\r\n    duk_call(ctx, 0);  // TypeError if not callable / undefined\r\n    return 0;\r\n}\r\n```"}}