Title: Proposal: Lualib override plugins · Issue #973 · TypeScriptToLua/TypeScriptToLua · GitHub
Open Graph Title: Proposal: Lualib override plugins · Issue #973 · TypeScriptToLua/TypeScriptToLua
X Title: Proposal: Lualib override plugins · Issue #973 · TypeScriptToLua/TypeScriptToLua
Description: In the last 2 weeks we received two requests for the ability to modify lualib output with plugins. One for supplying an environment-specific implementation of __TS__New, and another for a specialized ArrayForEach implementation for an en...
Open Graph Description: In the last 2 weeks we received two requests for the ability to modify lualib output with plugins. One for supplying an environment-specific implementation of __TS__New, and another for a specializ...
X Description: In the last 2 weeks we received two requests for the ability to modify lualib output with plugins. One for supplying an environment-specific implementation of __TS__New, and another for a specializ...
Opengraph URL: https://github.com/TypeScriptToLua/TypeScriptToLua/issues/973
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Proposal: Lualib override plugins","articleBody":"In the last 2 weeks we received two requests for the ability to modify lualib output with plugins. One for supplying an environment-specific implementation of __TS__New, and another for a specialized ArrayForEach implementation for an environment's special tables.\r\n\r\nOther use cases for overriding lualib functions might be using computation/memory/garbage optimized versions of lualib functions.\r\n\r\nI think this is a 'quick win' as it seems relatively simple to implement this as follows:\r\n\r\nAdd a record to the plugin interface that allows supplying a string for a lualib feature:\r\n\r\n```diff\r\nexport interface Plugin {\r\n /**\r\n * An augmentation to the map of visitors that transform TypeScript AST to Lua AST.\r\n *\r\n * Key is a `SyntaxKind` of a processed node.\r\n */\r\n visitors?: Visitors;\r\n\r\n /**\r\n * A function that converts Lua AST to a string.\r\n *\r\n * At most one custom printer can be provided across all plugins.\r\n */\r\n printer?: Printer;\r\n+\r\n+ /**\r\n+ * Provide a custom string that will be emitted as implementation for a lualib feature.\r\n+ */\r\n+ lualib?: Partial\u003cRecord\u003cLuaLibFeature, string\u003e\u003e\r\n}\r\n```\r\n\r\nThen a plugin could look like this:\r\n```ts\r\nconst plugin = {\r\n lualib: {\r\n [LuaLibFeature.Delete]: `\r\n function __TS__Delete(target, key)\r\n target[key] = nil\r\n end\r\n `\r\n }\r\n}\r\n```\r\n\r\nOr even:\r\n```ts\r\nconst plugin = {\r\n lualib: {\r\n ...garbageCollectorOptimizedLualibCollectionFromNpmPackage,\r\n ...lualibFunctionsForEnvironment\r\n }\r\n}\r\n```\r\n\r\nWe then pass these plugins to the printer and override the lualib methods it wants to emit.\r\n\r\nWhat I'm not sure about yet is if these should be supplied as Lua string or something else (TS/Lua AST/TS AST). Also leaving in the function header like I did in the example could potentially lead to typos and other issues, although we should easily be able to put in a diagnostic for that.\r\n","author":{"url":"https://github.com/Perryvw","@type":"Person","name":"Perryvw"},"datePublished":"2021-01-29T20:03:34.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/973/TypeScriptToLua/issues/973"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:874b596c-b319-887d-acac-d2d1438bf0c9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EAB4:3476BC:F28D9A:152A0A5:6970C533 |
| html-safe-nonce | 23fb965ba73786f203f962645332c5c182eb77feac5db5c4f7f97ef1c2d435f6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQUI0OjM0NzZCQzpGMjhEOUE6MTUyQTBBNTo2OTcwQzUzMyIsInZpc2l0b3JfaWQiOiIyNjM4MjczMTAwNDc3MDg0NjciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 677debd1f095a73976b7fd0a9f067e1767e1b4eca4484521eec3b93750657e23 |
| hovercard-subject-tag | issue:797151484 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/TypeScriptToLua/TypeScriptToLua/973/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cd25c52354533d4faca125e86fd324675c67a3a2b6e2f716cc7ccf4a7cae5e2f/TypeScriptToLua/TypeScriptToLua/issues/973 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cd25c52354533d4faca125e86fd324675c67a3a2b6e2f716cc7ccf4a7cae5e2f/TypeScriptToLua/TypeScriptToLua/issues/973 |
| og:image:alt | In the last 2 weeks we received two requests for the ability to modify lualib output with plugins. One for supplying an environment-specific implementation of __TS__New, and another for a specializ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Perryvw |
| hostname | github.com |
| expected-hostname | github.com |
| None | bb43a7bc61aba1b91c3c5cf8e7d00342e1e77a0cfe55a141222dbd7f9782d26f |
| turbo-cache-control | no-preview |
| go-import | github.com/TypeScriptToLua/TypeScriptToLua git https://github.com/TypeScriptToLua/TypeScriptToLua.git |
| octolytics-dimension-user_id | 44121206 |
| octolytics-dimension-user_login | TypeScriptToLua |
| octolytics-dimension-repository_id | 115876595 |
| octolytics-dimension-repository_nwo | TypeScriptToLua/TypeScriptToLua |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 115876595 |
| octolytics-dimension-repository_network_root_nwo | TypeScriptToLua/TypeScriptToLua |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 34817b01ad7cdf8b2beb35ea7b0e2a7609004eff |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width