{"id":15002205,"url":"https://github.com/repcomm/mt-api","last_synced_at":"2025-05-06T20:12:30.231Z","repository":{"id":153147159,"uuid":"628320730","full_name":"RepComm/mt-api","owner":"RepComm","description":"TypeScript definitions for base minetest API, for use with typescript-to-lua","archived":false,"fork":false,"pushed_at":"2023-04-23T18:12:19.000Z","size":52,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-04T16:16:37.861Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RepComm.png","metadata":{"files":{"readme":"ReadMe.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-04-15T15:27:35.000Z","updated_at":"2025-03-29T04:12:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"44446a62-9603-40e0-9a45-a2d868a9c0f3","html_url":"https://github.com/RepComm/mt-api","commit_stats":{"total_commits":18,"total_committers":1,"mean_commits":18.0,"dds":0.0,"last_synced_commit":"c8e54b16c49e350093228b1223210f206621f252"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RepComm%2Fmt-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RepComm%2Fmt-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RepComm%2Fmt-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RepComm%2Fmt-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RepComm","download_url":"https://codeload.github.com/RepComm/mt-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252761236,"owners_count":21800127,"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":[],"created_at":"2024-09-24T18:34:12.769Z","updated_at":"2025-05-06T20:12:30.211Z","avatar_url":"https://github.com/RepComm.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mt-api\nType definitions for using the minetest API\n\n## using\nInstall dev dependency in your typescript project:\n```\nnpm i @repcomm/mt-api --save-dev\n```\n\nAnd use:\n```\nimport type {} from \"@repcomm/mt-api\";\n```\n\nThe module declares the minetest global the same way you'd use it in lua\u003cbr/\u003e\nyou can also utilize the types it provides in your own code by importing them:\n\n```\nimport type { MtVec3 } from \"@repcomm/mt-api\";\n\nlet myVec: MtVec3 = { x: 0, y: 0, z: 0 };\n```\n\n## implemented\n- minetest global namespace\n```ts\nminetest.register_on_joinplayer( (player)=\u003e{\n  let playername = player:get_player_name();\n\n  minetest.chat_send_player(playername, \"Welcome!\")\n} );\n```\n\n## dev-dependencies\n- [ts-to-lua](https://github.com/TypeScriptToLua/TypeScriptToLua)\n- [lua-types](https://github.com/TypeScriptToLua/lua-types)\n\n## contributors (any contributions welcome, thank you!)\n- [repcomm](https://github.com/RepComm)\n\n## also see\n- [mt-visible-wielditem-api](https://github.com/RepComm/mt-visible-wielditem-api)\n- [mt-3d-armor-api](https://github.com/RepComm/mt-3d-armor-api)\n\n## contributing\nUsers of minetest's lua api will noticed a lack of `\":\"` in typescript\n\nLua uses `obj:method` and `obj.func` to differentiate with `obj` is passed as `self` as the first argument\n\nFor instance:\n```lua\nlocal obj = {\n  method = function (self)\n    --\"self\" refers to obj, similar to \"this\" in typescript\n  end\n\n  func = function ()\n    --no self variable here\n  end\n};\n\nobj.method() -- self will be nil\nobj:method() -- self will be obj\n\nobj.func() -- self will be nil\nobj:func() -- self will still be nil because its not declared in function args\n```\n\nIn typescript this is handled by providing a `this` definition:\n```ts\ninterface MinetestGlobal {\n  register_on_joinplayer (this: void, cb: MtPlayerJoinCallback): void;\n}\ndeclare global minetest: MinetestGlobal;\n```\n\nBecause\n```ts\nthis: void\n```\nTypeScript calls to `minetest.register_on_joinplayer()` will properly output:\n`minetest.register_on_joinplayer()` in lua\n\nWithout providing `this: void`, this would generate:\n`minetest:register_on_joinplayer()` as typescript-to-lua compiler assumes we want to provide a `self` reference as first argument\n\nOn the flip-side:\n```lua\nfunction handle_player_join (player) --player is ObjRef\n  player:get_player_name() -- passes player as first arg to get_player_name code\nend\n\nminetest.register_on_joinplayer ( handle_player_join )\n```\n\nIn typescript definitions:\n```ts\ninterface ObjRef {\n  //implicit this: ObjRef\n  get_player_name(): string;\n  //same as\n  get_player_name(this: ObjRef): string;\n}\n```\nWhich both properly output:\n\n```lua\nplayer:get_player_name()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frepcomm%2Fmt-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frepcomm%2Fmt-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frepcomm%2Fmt-api/lists"}