From c1485c160f2cc1f169cc34c2055fb7b4b84b2c7e Mon Sep 17 00:00:00 2001 From: IcyLava Date: Sun, 5 Mar 2023 19:28:58 +0200 Subject: [PATCH 1/3] Add defs for baton, flux and log.lua --- types/baton/baton.d.tl | 36 ++++++++++++++++++++++++ types/flux/flux.d.tl | 57 ++++++++++++++++++++++++++++++++++++++ types/rxi-log-lua/log.d.tl | 24 ++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 types/baton/baton.d.tl create mode 100644 types/flux/flux.d.tl create mode 100644 types/rxi-log-lua/log.d.tl diff --git a/types/baton/baton.d.tl b/types/baton/baton.d.tl new file mode 100644 index 0000000..8f8352b --- /dev/null +++ b/types/baton/baton.d.tl @@ -0,0 +1,36 @@ +-- Depends on love definition from https://github.com/MikuAuahDark/love2d-tl + +local record baton + record Configuration + controls: {string:{string}} + pairs: {string:{string, string, string, string}} + joystick: love.joystick.Joystick + deadzone: number + squareDeadzone: boolean + end + + enum ActiveDevice + "kbm" + "joy" + "none" + end + + record Player + config: Configuration + + update: function(self: Player) + getRaw: function(self: Player, name: string): number + get: function(self: Player, name: string): number + get: function(self: Player, name: string): number, number + down: function(self: Player, name: string): boolean + pressed: function(self: Player, name: string): boolean + released: function(self: Player, name: string): boolean + + getActiveDevice: function(self: Player): ActiveDevice + _activeDevice: ActiveDevice + end + + new: function(config: Configuration): Player +end + +return baton \ No newline at end of file diff --git a/types/flux/flux.d.tl b/types/flux/flux.d.tl new file mode 100644 index 0000000..91ddb51 --- /dev/null +++ b/types/flux/flux.d.tl @@ -0,0 +1,57 @@ +local record flux + enum Easing + "linear" + "quadin" + "quadout" + "quadinout" + "cubicin" + "cubicout" + "cubicinout" + "quartin" + "quartout" + "quartinout" + "quintin" + "quintout" + "quintinout" + "expoin" + "expoout" + "expoinout" + "sinein" + "sineout" + "sineinout" + "circin" + "circout" + "circinout" + "backin" + "backout" + "backinout" + "elasticin" + "elasticout" + "elasticinout" + end + + record Tween + ease: function(self: Tween, type: Easing): Tween + delay: function(self: Tween, time: number): Tween + onstart: function(self: Tween, function()): Tween + onupdate: function(self: Tween, function()): Tween + oncomplete: function(self: Tween, function()): Tween + after: function(self: Tween, time: number, vars: U): Tween + after: function(self: Tween, obj: U, time: number, vars: U): Tween + stop: function(self: Tween) + end + + record Group + update: function(self: Group, deltatime: number) + to: function(self: Group, obj: {K:V}, time: number, vars: {K:V}): Tween<{K:V}> + to: function(self: Group, obj: T, time: number, vars: T): Tween + -- group: function(self: Group): Group + end + + update: function(deltatime: number) + to: function(obj: {K:V}, time: number, vars: {K:V}): Tween<{K:V}> + to: function(obj: T, time: number, vars: T): Tween + group: function(): Group +end + +return flux \ No newline at end of file diff --git a/types/rxi-log-lua/log.d.tl b/types/rxi-log-lua/log.d.tl new file mode 100644 index 0000000..251e921 --- /dev/null +++ b/types/rxi-log-lua/log.d.tl @@ -0,0 +1,24 @@ +local record log + enum Level + "trace" + "debug" + "info" + "warn" + "error" + "fatal" + end + type LogFunction = function(...: any) + + usecolor: boolean + outfile: string + level: Level + + trace: LogFunction + debug: LogFunction + info: LogFunction + warn: LogFunction + error: LogFunction + fatal: LogFunction +end + +return log \ No newline at end of file From 3c959587e19c8013ba95e0faca519964ec0e3475 Mon Sep 17 00:00:00 2001 From: IcyLava Date: Sun, 5 Mar 2023 19:33:50 +0200 Subject: [PATCH 2/3] Make rxi-json-lua definition more specific --- types/rxi-json-lua/json.d.tl | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/types/rxi-json-lua/json.d.tl b/types/rxi-json-lua/json.d.tl index 3f8f171..d75e11d 100644 --- a/types/rxi-json-lua/json.d.tl +++ b/types/rxi-json-lua/json.d.tl @@ -1,9 +1,14 @@ local record json - -- Returns a string representing value encoded in JSON. - encode: function(value: any): string - - -- Returns a value representing the decoded JSON string. - decode: function(str: string): any + type Array = {Value} + type Object = {string:Value} + + -- Workaround for not being able to union Array and Object + type Mixed = {string|integer:Value} + + type Value = number | string | boolean | Mixed + + encode: function(value: Value): string + decode: function(str: string): Value end -return json +return json \ No newline at end of file From 59fefee79dee37ff7fea7d4bc6ac9b0706aecfec Mon Sep 17 00:00:00 2001 From: IcyLava Date: Tue, 7 Mar 2023 13:05:43 +0200 Subject: [PATCH 3/3] Make rxi-json-lua encode definition more lenient --- types/rxi-json-lua/json.d.tl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/types/rxi-json-lua/json.d.tl b/types/rxi-json-lua/json.d.tl index d75e11d..5407c73 100644 --- a/types/rxi-json-lua/json.d.tl +++ b/types/rxi-json-lua/json.d.tl @@ -7,7 +7,16 @@ local record json type Value = number | string | boolean | Mixed - encode: function(value: Value): string + -- For convenience, encode takes any type and may throw an error at runtime. + -- You can enforce correctness yourself by specifying types on variables or records. + -- + -- For example: + -- local obj: json.Object = {value = 'data'} + -- local encoded = json.encode(obj) + + encode: function(value: any): string + -- encode: function(value: Value): string + decode: function(str: string): Value end