ts-defold / type-gen Goto Github PK
View Code? Open in Web Editor NEWTypescript type generator for Defold
License: MIT License
Typescript type generator for Defold
License: MIT License
Currently constants are marked as any
and declared with let
and after browsing the source they appear to be of either number or string mostly, as well as indeed const
. The docs themselves do not directly inform if they are a number or a string constant, however it is not entirely important to type as they are exposed to lua from the C++ API.
In order to provide some additional TypeScript type safeness we could brand each constant per module so you do not use the wrong constant in the wrong namespace...
declare enum DefoldConstant { _ = "" }
declare let GENERIC_CONSTANT: DefoldConstant;
We could parse the docs for the use of the constant, and read the type from the call site, as so far it appears the constants at the call site are referred to as either a number
i,e resource.set_texture(path,table,buffer)
, a constant
i.e resource.store_manifest()
a constant | vector
i.e. go.animate()
.
declare enum DefoldResourceConstant { _ = "" }
declare type ResourceTextureConstant = DefoldResourceConstant | number & {
}
declare type ResourceLiveUpdateConstant = DefoldResourceConstant & {
}
In the case of go.animate()
the types are not directly called out and we would need to rely on some pattern matching. The parameter is named easing
it is a constant | vector
and we have constants that start with the name EASING_
...
declare enum DefoldGoConstant { _ = "" }
declare type GoEasingConstant = DefoldGoConstant | vmath.vector3 & {
}
export const EASING_INBACK: GoEasingConstant
The parser may need to be extended to store some additional context so that the generator can run some generation against the function calls in the module to determine naming convention and type.
Alternatively, constants could just be declared as constants scoped to the namespace, and the callsite itself go be modified when a number, vector, or some other constant type is presented to take either a scoped constant like ResourceConstant
| type
.
Need types for callback functions with param signatures.
https://defold.com/ref/stable/resource/#resource.store_manifest:manifest_buffer-callback
Defold has a problem parsing go.property
calls that are spread across multiple lines.
See: defold/defold#3342
If we make a call to a function, with another function call nested in tstl, the result is a multi-line expansion. They do this for better sourceMap support as there can only be one error per line. In order to work around this limitation the printer would need to be overriden in the printExpressionList
method here:
https://github.com/TypeScriptToLua/TypeScriptToLua/blob/master/src/LuaPrinter.ts#L744
When targeting 5.1 TypeScriptToLua currently doesn't support switch statements in Lua 5.1 (TypeScriptToLua/TypeScriptToLua#194). You are free to bump your target version but from my experience HTML5 seems to only work with Lua 5.1 as the target.
I would like to work on a PR for switch support in Lua 5.1, but have been told it is a hard problem to solve.
Need to mark return types that return multiple values as LuaMultiReturn
Source maps from TS -> Lua -> HTML5
Support type definitions for extensions.
.tsconfig
file, and not automatically included.According to the official document, bufferstream is an array-like object. And here is the source code: https://github.com/defold/defold/blob/869a87718757bdb7bfd6ed078047fa7bfb451de9/engine/gamesys/src/gamesys/scripts/script_buffer.cpp#L878
Any way to implement this feature?
Parse out types from functions that take table parameters and then have the arguments to the table defined in the documentation.
Example:
https://defold.com/ref/stable/resource/#resource.set_texture:path-table-buffer
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.