You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Other use cases for overriding lualib functions might be using computation/memory/garbage optimized versions of lualib functions.
I think this is a 'quick win' as it seems relatively simple to implement this as follows:
Add a record to the plugin interface that allows supplying a string for a lualib feature:
export interface Plugin {
/**
* An augmentation to the map of visitors that transform TypeScript AST to Lua AST.
*
* Key is a `SyntaxKind` of a processed node.
*/
visitors?: Visitors;
/**
* A function that converts Lua AST to a string.
*
* At most one custom printer can be provided across all plugins.
*/
printer?: Printer;
++ /**+ * Provide a custom string that will be emitted as implementation for a lualib feature.+ */+ lualib?: Partial<Record<LuaLibFeature, string>>
}
Then a plugin could look like this:
constplugin={lualib: {[LuaLibFeature.Delete]: ` function __TS__Delete(target, key) target[key] = nil end `}}
We then pass these plugins to the printer and override the lualib methods it wants to emit.
What 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.
The text was updated successfully, but these errors were encountered:
It could also be nice if plugins can also control the outputting of lualib feature itself (for optimizations or modifications), beyond just the lualib function contents.
This could potentially be expanded to allowing plugins to override builtin function behavior in general.
I think its better if lualib functions can be supplied as TS code, and tstl can compile them in a separate "instance", like how lualib is currently compiled.
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.
Other use cases for overriding lualib functions might be using computation/memory/garbage optimized versions of lualib functions.
I think this is a 'quick win' as it seems relatively simple to implement this as follows:
Add a record to the plugin interface that allows supplying a string for a lualib feature:
Then a plugin could look like this:
Or even:
We then pass these plugins to the printer and override the lualib methods it wants to emit.
What 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.
The text was updated successfully, but these errors were encountered: