{"id":16085356,"url":"https://github.com/AGulev/jstodef","last_synced_at":"2025-10-23T02:30:23.429Z","repository":{"id":53137554,"uuid":"174534264","full_name":"AGulev/jstodef","owner":"AGulev","description":"Library for sending messages from JavaScript to Defold (Lua)","archived":false,"fork":false,"pushed_at":"2025-01-01T21:13:11.000Z","size":53,"stargazers_count":41,"open_issues_count":2,"forks_count":7,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-02-06T17:57:22.032Z","etag":null,"topics":["defold","defold-game-engine","defold-library","emscripten","lua"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AGulev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-08T12:30:01.000Z","updated_at":"2025-01-06T18:31:06.000Z","dependencies_parsed_at":"2024-04-10T09:27:19.934Z","dependency_job_id":"bb64f309-6266-4abc-a4b5-47e9f4b36627","html_url":"https://github.com/AGulev/jstodef","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AGulev%2Fjstodef","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AGulev%2Fjstodef/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AGulev%2Fjstodef/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AGulev%2Fjstodef/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AGulev","download_url":"https://codeload.github.com/AGulev/jstodef/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237763855,"owners_count":19362310,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["defold","defold-game-engine","defold-library","emscripten","lua"],"created_at":"2024-10-09T13:01:55.647Z","updated_at":"2025-10-23T02:30:23.095Z","avatar_url":"https://github.com/AGulev.png","language":"C++","readme":"# JsToDef\n\n[![Build Status](https://github.com/AGulev/jstodef/workflows/Build%20with%20bob/badge.svg)](https://github.com/AGulev/jstodef/actions)\n\nThis is [Native Extension](https://www.defold.com/manuals/extensions/) for the [Defold Game Engine](https://www.defold.com) that makes possible to send messages from JavaScript to Lua in [HTML5 build](https://www.defold.com/manuals/html5/).\n\n## Installation\nTo use this library in your Defold project, add the needed version URL to your `game.project` dependencies from [Releases](https://github.com/AGulev/jstodef/releases)\n\n\u003cimg width=\"401\" alt=\"image\" src=\"https://user-images.githubusercontent.com/2209596/202223571-c77f0304-5202-4314-869d-7a90bbeec5ec.png\"\u003e\n\n## API JavaScript side\n\n`JsToDef.send(message_id, message)`\n\nWhere `message_id` is a string that helps you to identify this message on Lua side.\n\n`message` is a custom value that might be one of the next types: object, number, boolean, string, undefined(if you don't need any extra data).\n\n##### Example:\n\n```javascript\nJsToDef.send(\"MyCustomMessageName\", \"custom message\");\nJsToDef.send(\"ObjectEvent\", {foo:\"bar\", num:16, isAv:true});\nJsToDef.send(\"FloatEvent\", 19.2);\nJsToDef.send(\"IntEvent\", 18);\nJsToDef.send(\"StrintEvent\", \"custom string\");\nJsToDef.send(\"EmptyEvent\");\nJsToDef.send(\"BooleanEvent\", true);\nJsToDef.send(\"BooleanEvent\", false);\n```\n\n## API Lua side\n\nIf you are working on cross-platform application the best practice to check the existence of jstodef module, this module exists only in html5 build:\n```lua\nif jstodef then\n  -- any operations with jstodef\nend\n```\n### Add Listener\n\n`jstodef.add_listener(listener)`\n\nWhere `listener` is a function with the next parameters:\n\n`self` is the current script self.\n\n`message_id` is a string that helps you to identify this message.\n\n`message` is a custom value that might be one of the next types: table, number, boolean, string, nil.\n\nIt is possible to add a few listeners.\n\n##### Example:\n\n```lua\nlocal function js_listener(self, message_id, message)\n  if message_id == \"MyCustomMessageName\" then\n    -- do something\n  end\nend\n\nfunction init(self)\n  if jstodef then\n    jstodef.add_listener(js_listener)\n  end\nend\n```\n\n### Remove Listener\n\n`jstodef.remove_listener(listener)`\n\nWhere `listener` is the function that was previously added as a listener with `jstodef.add_listener()` method.\n\n```lua\nfunction final(self)\n  if jstodef then\n    jstodef.remove_listener(js_listener)\n  end\nend\n```\n\n## Issues and suggestions\n\nIf you have any issues, questions or suggestions please [create an issue](https://github.com/agulev/jstodef/issues) or contact me: me@agulev.com\n","funding_links":[],"categories":["Libraries"],"sub_categories":["Programming Language"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAGulev%2Fjstodef","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAGulev%2Fjstodef","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAGulev%2Fjstodef/lists"}