Skip to content

Commit ccb6ca5

Browse files
Structs (#142)
1 parent 921ff2f commit ccb6ca5

File tree

19 files changed

+960
-658
lines changed

19 files changed

+960
-658
lines changed

.stylua.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
syntax = "Lua51"
2+
indent_type = "Spaces"
3+
indent_width = 2
4+
5+
[sort_requires]
6+
enabled = true

astra/lua/astra.d.lua

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
---@class Astra
44
Astra = {
5-
version = "@ASTRA_VERSION",
5+
version = "@ASTRA_VERSION",
66
}
77

88
ASTRA_INTERNAL__CURRENT_SCRIPT = ""
@@ -14,14 +14,14 @@ ASTRA_INTERNAL__CURRENT_SCRIPT = ""
1414
---Pretty prints any table or value
1515
---@param value any
1616
function pprint(...)
17-
---@diagnostic disable-next-line: undefined-global
18-
astra_internal__pretty_print(...)
17+
---@diagnostic disable-next-line: undefined-global
18+
astra_internal__pretty_print(...)
1919
end
2020

2121
---@return string
2222
function uuid()
23-
---@diagnostic disable-next-line: undefined-global
24-
return astra_internal__uuid()
23+
---@diagnostic disable-next-line: undefined-global
24+
return astra_internal__uuid()
2525
end
2626

2727
---Invalidates imported module cache
@@ -30,8 +30,8 @@ end
3030
---function to remove those caches
3131
---@param path string
3232
function invalidate_cache(path)
33-
---@diagnostic disable-next-line: undefined-global
34-
astra_internal__invalidate_cache(path)
33+
---@diagnostic disable-next-line: undefined-global
34+
astra_internal__invalidate_cache(path)
3535
end
3636

3737
---Represents an async task
@@ -43,26 +43,26 @@ end
4343
---@param callback fun() The callback to run the content of the async task
4444
---@return TaskHandler
4545
function spawn_task(callback)
46-
---@diagnostic disable-next-line: undefined-global
47-
return astra_internal__spawn_task(callback)
46+
---@diagnostic disable-next-line: undefined-global
47+
return astra_internal__spawn_task(callback)
4848
end
4949

5050
---Starts a new async task with a delay in milliseconds
5151
---@param callback fun() The callback to run the content of the async task
5252
---@param timeout number The delay in milliseconds
5353
---@return TaskHandler
5454
function spawn_timeout(callback, timeout)
55-
---@diagnostic disable-next-line: undefined-global
56-
return astra_internal__spawn_timeout(callback, timeout)
55+
---@diagnostic disable-next-line: undefined-global
56+
return astra_internal__spawn_timeout(callback, timeout)
5757
end
5858

5959
---Starts a new async task that runs infinitely in a loop but with a delay in milliseconds
6060
---@param callback fun() The callback to run the content of the async task
6161
---@param timeout number The delay in milliseconds
6262
---@return TaskHandler
6363
function spawn_interval(callback, timeout)
64-
---@diagnostic disable-next-line: undefined-global
65-
return astra_internal__spawn_interval(callback, timeout)
64+
---@diagnostic disable-next-line: undefined-global
65+
return astra_internal__spawn_interval(callback, timeout)
6666
end
6767

6868
---Splits a sentence into an array given the separator
@@ -71,18 +71,18 @@ end
7171
---@return table array
7272
---@nodiscard
7373
function string.split(input_str, separator_str)
74-
local result_table = {}
75-
for word in input_str:gmatch("([^" .. separator_str .. "]+)") do
76-
table.insert(result_table, word)
77-
end
78-
return result_table
74+
local result_table = {}
75+
for word in input_str:gmatch("([^" .. separator_str .. "]+)") do
76+
table.insert(result_table, word)
77+
end
78+
return result_table
7979
end
8080

8181
---Load your own file into env
8282
---@param file_path string
8383
function dotenv_load(file_path)
84-
---@diagnostic disable-next-line: undefined-global
85-
return astra_internal__dotenv_load(file_path)
84+
---@diagnostic disable-next-line: undefined-global
85+
return astra_internal__dotenv_load(file_path)
8686
end
8787

8888
dotenv_load(".env")
@@ -101,14 +101,14 @@ dotenv_load(".env.local")
101101
---@param expression string
102102
---@return Regex
103103
function regex(expression)
104-
---@diagnostic disable-next-line: undefined-global
105-
return astra_internal__regex(expression)
104+
---@diagnostic disable-next-line: undefined-global
105+
return astra_internal__regex(expression)
106106
end
107107

108108
---@param key string
109109
function os.getenv(key)
110-
---@diagnostic disable-next-line: undefined-global
111-
return astra_internal__getenv(key)
110+
---@diagnostic disable-next-line: undefined-global
111+
return astra_internal__getenv(key)
112112
end
113113

114114
---Sets the environment variable.
@@ -117,6 +117,6 @@ end
117117
---@param key string
118118
---@param value string
119119
function os.setenv(key, value)
120-
---@diagnostic disable-next-line: undefined-global
121-
return astra_internal__setenv(key, value)
120+
---@diagnostic disable-next-line: undefined-global
121+
return astra_internal__setenv(key, value)
122122
end

astra/lua/crypto.lua

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ local crypto = {}
77
---@param input string The input to be hashed
88
---@return string
99
function crypto.hash(hash_type, input)
10-
---@diagnostic disable-next-line: undefined-global
11-
return astra_internal__hash(hash_type, input)
10+
---@diagnostic disable-next-line: undefined-global
11+
return astra_internal__hash(hash_type, input)
1212
end
1313

1414
crypto.base64 = {}
@@ -17,32 +17,32 @@ crypto.base64 = {}
1717
---@param input string The input to be encoded
1818
---@return string
1919
function crypto.base64.encode(input)
20-
---@diagnostic disable-next-line: undefined-global
21-
return astra_internal__base64_encode(input)
20+
---@diagnostic disable-next-line: undefined-global
21+
return astra_internal__base64_encode(input)
2222
end
2323

2424
---Encodes the given input as Base64 but URL safe
2525
---@param input string The input to be encoded
2626
---@return string
2727
function crypto.base64.encode_urlsafe(input)
28-
---@diagnostic disable-next-line: undefined-global
29-
return astra_internal__base64_encode_urlsafe(input)
28+
---@diagnostic disable-next-line: undefined-global
29+
return astra_internal__base64_encode_urlsafe(input)
3030
end
3131

3232
---Decodes the given input as Base64
3333
---@param input string The input to be decoded
3434
---@return string
3535
function crypto.base64.decode(input)
36-
---@diagnostic disable-next-line: undefined-global
37-
return astra_internal__base64_decode(input)
36+
---@diagnostic disable-next-line: undefined-global
37+
return astra_internal__base64_decode(input)
3838
end
3939

4040
---Decodes the given input as Base64 but URL safe
4141
---@param input string The input to be decoded
4242
---@return string
4343
function crypto.base64.decode_urlsafe(input)
44-
---@diagnostic disable-next-line: undefined-global
45-
return astra_internal__base64_decode_urlsafe(input)
44+
---@diagnostic disable-next-line: undefined-global
45+
return astra_internal__base64_decode_urlsafe(input)
4646
end
4747

4848
return crypto

astra/lua/database.lua

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,17 @@
2222
---@return Database Database that represents the SQL connection.
2323
---@nodiscard
2424
local function connect(database_type, url, connection_options)
25-
if not connection_options then
26-
connection_options = {}
27-
end
28-
connection_options.max_connections = connection_options.max_connections
29-
connection_options.extensions = connection_options.extensions or {}
30-
connection_options.extensions_with_entrypoint = connection_options.extensions_with_entrypoint or
31-
{} -- SQLite only
32-
connection_options.is_immutable = connection_options.is_immutable ~= nil and connection_options.is_immutable or
33-
false -- SQLite only
34-
connection_options.other_options = connection_options.other_options or {}
25+
if not connection_options then
26+
connection_options = {}
27+
end
28+
connection_options.max_connections = connection_options.max_connections
29+
connection_options.extensions = connection_options.extensions or {}
30+
connection_options.extensions_with_entrypoint = connection_options.extensions_with_entrypoint or {} -- SQLite only
31+
connection_options.is_immutable = connection_options.is_immutable ~= nil and connection_options.is_immutable or false -- SQLite only
32+
connection_options.other_options = connection_options.other_options or {}
3533

36-
---@diagnostic disable-next-line: undefined-global
37-
return astra_internal__database_connect(database_type, url, connection_options)
34+
---@diagnostic disable-next-line: undefined-global
35+
return astra_internal__database_connect(database_type, url, connection_options)
3836
end
3937

4038
return { new = connect }

astra/lua/datetime.lua

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,25 @@
3636
---@param differentiator? string | number This field can be used to determine the type of DateTime. On empty it creates a new local DateTime, on number it starts te sequence for letting you define the DateTime by parameters, and on string it allows you to parse a string to DateTime.
3737
---@return DateTime
3838
local function new_datetime(differentiator, month, day, hour, min, sec, milli)
39-
if type(differentiator) == "string" then
40-
---@diagnostic disable-next-line: undefined-global
41-
return astra_internal__datetime_new_parse(differentiator)
42-
elseif type(differentiator) == "number" then
43-
---@diagnostic disable-next-line: undefined-global
44-
return astra_internal__datetime_new_from(differentiator, month, day, hour, min, sec, milli)
45-
else
46-
---@diagnostic disable-next-line: undefined-global
47-
return astra_internal__datetime_new_now()
48-
end
39+
if type(differentiator) == "string" then
40+
---@diagnostic disable-next-line: undefined-global
41+
return astra_internal__datetime_new_parse(differentiator)
42+
elseif type(differentiator) == "number" then
43+
---@diagnostic disable-next-line: undefined-global
44+
return astra_internal__datetime_new_from(differentiator, month, day, hour, min, sec, milli)
45+
else
46+
---@diagnostic disable-next-line: undefined-global
47+
return astra_internal__datetime_new_now()
48+
end
4949
end
5050

5151
---@type fun(differentiator?: string | number, month: number?, day: number?, hour: number?, min: number?, sec: number?, milli: number?): DateTime
5252
---@param differentiator? string | number This field can be used to determine the type of DateTime. On empty it creates a new local DateTime, on number it starts te sequence for letting you define the DateTime by parameters, and on string it allows you to parse a string to DateTime.
5353
---@return DateTime
5454
--- Creates a wrapper for a DateTime-like object
5555
local function datetime_new(differentiator, month, day, hour, min, sec, milli)
56-
-- Create real DateTime using datetime
57-
return new_datetime(differentiator, month, day, hour, min, sec, milli)
56+
-- Create real DateTime using datetime
57+
return new_datetime(differentiator, month, day, hour, min, sec, milli)
5858
end
5959

6060
return { new = datetime_new }

0 commit comments

Comments
 (0)