lenix 1.3.4 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,370 @@
1
+ {
2
+ "outFile": "eslint.config.mts",
3
+ "rules": {
4
+ "accessor-pairs": "error",
5
+ "array-callback-return": "warn",
6
+ "arrow-body-style": "error",
7
+ "block-scoped-var": "error",
8
+ "camelcase": "error",
9
+ "capitalized-comments": "warn",
10
+ "class-methods-use-this": "error",
11
+ "complexity": "warn",
12
+ "consistent-return": "warn",
13
+ "consistent-this": "warn",
14
+ "constructor-super": "warn",
15
+ "curly": [
16
+ "error",
17
+ "multi"
18
+ ],
19
+ "default-case": "error",
20
+ "default-case-last": "error",
21
+ "default-param-last": "error",
22
+ "dot-notation": "error",
23
+ "eqeqeq": "error",
24
+ "for-direction": "error",
25
+ "func-name-matching": "error",
26
+ "func-names": "warn",
27
+ "func-style": "error",
28
+ "getter-return": "error",
29
+ "grouped-accessor-pairs": "error",
30
+ "guard-for-in": "warn",
31
+ "id-denylist": "warn",
32
+ "id-length": [
33
+ "error",
34
+ {
35
+ "exceptions": [
36
+ "_"
37
+ ]
38
+ }
39
+ ],
40
+ "id-match": "error",
41
+ "init-declarations": "error",
42
+ "logical-assignment-operators": "error",
43
+ "max-classes-per-file": "error",
44
+ "max-depth": "error",
45
+ "max-lines": "error",
46
+ "max-lines-per-function": "warn",
47
+ "max-nested-callbacks": "error",
48
+ "max-params": "error",
49
+ "max-statements": "error",
50
+ "new-cap": "warn",
51
+ "no-alert": "error",
52
+ "no-array-constructor": "warn",
53
+ "no-async-promise-executor": "warn",
54
+ "no-await-in-loop": "warn",
55
+ "no-bitwise": "warn",
56
+ "no-caller": "warn",
57
+ "no-case-declarations": "warn",
58
+ "no-class-assign": "error",
59
+ "no-compare-neg-zero": "error",
60
+ "no-cond-assign": "warn",
61
+ "no-console": "warn",
62
+ "no-const-assign": "error",
63
+ "no-constant-binary-expression": "warn",
64
+ "no-constant-condition": "warn",
65
+ "no-constructor-return": "error",
66
+ "no-continue": "error",
67
+ "no-control-regex": "warn",
68
+ "no-debugger": "error",
69
+ "no-delete-var": "error",
70
+ "no-div-regex": "warn",
71
+ "no-dupe-args": "error",
72
+ "no-dupe-class-members": "error",
73
+ "no-dupe-else-if": "error",
74
+ "no-dupe-keys": "error",
75
+ "no-duplicate-case": "error",
76
+ "no-duplicate-imports": "error",
77
+ "no-else-return": "error",
78
+ "no-empty": "error",
79
+ "no-empty-character-class": "warn",
80
+ "no-empty-function": "error",
81
+ "no-empty-pattern": "error",
82
+ "no-empty-static-block": "error",
83
+ "no-eq-null": "error",
84
+ "no-eval": "error",
85
+ "no-ex-assign": "error",
86
+ "no-extend-native": "warn",
87
+ "no-extra-bind": "warn",
88
+ "no-extra-boolean-cast": "warn",
89
+ "no-extra-label": "warn",
90
+ "no-fallthrough": "warn",
91
+ "no-func-assign": "error",
92
+ "no-global-assign": "error",
93
+ "no-implicit-coercion": "warn",
94
+ "no-implicit-globals": "error",
95
+ "no-implied-eval": "error",
96
+ "no-import-assign": "error",
97
+ "no-inline-comments": "warn",
98
+ "no-inner-declarations": "error",
99
+ "no-invalid-regexp": "warn",
100
+ "no-invalid-this": "error",
101
+ "no-irregular-whitespace": "warn",
102
+ "no-iterator": "warn",
103
+ "no-label-var": "error",
104
+ "no-labels": "error",
105
+ "no-lone-blocks": "error",
106
+ "no-lonely-if": "error",
107
+ "no-loop-func": "warn",
108
+ "no-loss-of-precision": "error",
109
+ "no-magic-numbers": [
110
+ "error",
111
+ {
112
+ "detectObjects": true,
113
+ "enforceConst": true,
114
+ "ignore": [
115
+ 0,
116
+ 1
117
+ ],
118
+ "ignoreReadonlyClassProperties": true
119
+ }
120
+ ],
121
+ "no-misleading-character-class": "warn",
122
+ "no-multi-assign": "error",
123
+ "no-multi-str": "error",
124
+ "no-negated-condition": "warn",
125
+ "no-nested-ternary": "error",
126
+ "no-new": "error",
127
+ "no-new-func": "error",
128
+ "no-new-native-nonconstructor": "warn",
129
+ "no-new-wrappers": "warn",
130
+ "no-nonoctal-decimal-escape": "warn",
131
+ "no-obj-calls": "warn",
132
+ "no-object-constructor": "warn",
133
+ "no-octal": "error",
134
+ "no-octal-escape": "warn",
135
+ "no-param-reassign": "warn",
136
+ "no-plusplus": "warn",
137
+ "no-promise-executor-return": "error",
138
+ "no-proto": "warn",
139
+ "no-prototype-builtins": "warn",
140
+ "no-redeclare": "error",
141
+ "no-regex-spaces": "warn",
142
+ "no-restricted-exports": "error",
143
+ "no-restricted-globals": "warn",
144
+ "no-restricted-imports": "warn",
145
+ "no-restricted-properties": "warn",
146
+ "no-restricted-syntax": "warn",
147
+ "no-return-assign": "error",
148
+ "no-script-url": "warn",
149
+ "no-self-assign": "error",
150
+ "no-self-compare": "error",
151
+ "no-sequences": "warn",
152
+ "no-setter-return": "error",
153
+ "no-shadow": "warn",
154
+ "no-shadow-restricted-names": "error",
155
+ "no-sparse-arrays": "error",
156
+ "no-template-curly-in-string": "error",
157
+ "no-this-before-super": "error",
158
+ "no-throw-literal": "error",
159
+ "no-unassigned-vars": "error",
160
+ "no-undef": "error",
161
+ "no-undef-init": "error",
162
+ "no-undefined": "off",
163
+ "no-underscore-dangle": "warn",
164
+ "no-unexpected-multiline": "error",
165
+ "no-unmodified-loop-condition": "warn",
166
+ "no-unneeded-ternary": "error",
167
+ "no-unreachable": "error",
168
+ "no-unreachable-loop": "warn",
169
+ "no-unsafe-finally": "warn",
170
+ "no-unsafe-negation": "warn",
171
+ "no-unsafe-optional-chaining": "error",
172
+ "no-unused-expressions": "error",
173
+ "no-unused-labels": "error",
174
+ "no-unused-private-class-members": "error",
175
+ "no-unused-vars": "error",
176
+ "no-use-before-define": "error",
177
+ "no-useless-assignment": "error",
178
+ "no-useless-backreference": "warn",
179
+ "no-useless-call": "warn",
180
+ "no-useless-catch": "error",
181
+ "no-useless-computed-key": "warn",
182
+ "no-useless-concat": "error",
183
+ "no-useless-constructor": "warn",
184
+ "no-useless-escape": "warn",
185
+ "no-useless-rename": "error",
186
+ "no-useless-return": "error",
187
+ "no-var": "error",
188
+ "no-void": "error",
189
+ "no-warning-comments": "warn",
190
+ "no-with": "error",
191
+ "object-shorthand": "error",
192
+ "one-var": "off",
193
+ "operator-assignment": "warn",
194
+ "prefer-arrow-callback": "error",
195
+ "prefer-const": "error",
196
+ "prefer-destructuring": "error",
197
+ "prefer-exponentiation-operator": "error",
198
+ "prefer-named-capture-group": "warn",
199
+ "prefer-numeric-literals": "warn",
200
+ "prefer-object-has-own": "warn",
201
+ "prefer-object-spread": "error",
202
+ "prefer-promise-reject-errors": "warn",
203
+ "prefer-regex-literals": "warn",
204
+ "prefer-rest-params": "error",
205
+ "prefer-spread": "error",
206
+ "prefer-template": "error",
207
+ "preserve-caught-error": "error",
208
+ "radix": "warn",
209
+ "require-atomic-updates": "warn",
210
+ "require-await": "error",
211
+ "require-unicode-regexp": "warn",
212
+ "require-yield": "error",
213
+ "sort-imports": "off",
214
+ "sort-keys": "off",
215
+ "sort-vars": "error",
216
+ "strict": "error",
217
+ "symbol-description": "error",
218
+ "unicode-bom": "warn",
219
+ "use-isnan": "error",
220
+ "valid-typeof": "error",
221
+ "vars-on-top": "error",
222
+ "yoda": "error",
223
+ "@typescript-eslint/adjacent-overload-signatures": "error",
224
+ "@typescript-eslint/array-type": "error",
225
+ "@typescript-eslint/ban-ts-comment": "error",
226
+ "@typescript-eslint/ban-tslint-comment": "error",
227
+ "@typescript-eslint/class-literal-property-style": "warn",
228
+ "@typescript-eslint/class-methods-use-this": "warn",
229
+ "@typescript-eslint/consistent-generic-constructors": "error",
230
+ "@typescript-eslint/consistent-indexed-object-style": "error",
231
+ "@typescript-eslint/consistent-type-assertions": "error",
232
+ "@typescript-eslint/consistent-type-definitions": "error",
233
+ "@typescript-eslint/consistent-type-imports": "error",
234
+ "@typescript-eslint/default-param-last": "warn",
235
+ "@typescript-eslint/explicit-function-return-type": "off",
236
+ "@typescript-eslint/explicit-member-accessibility": "warn",
237
+ "@typescript-eslint/explicit-module-boundary-types": "off",
238
+ "@typescript-eslint/init-declarations": "error",
239
+ "@typescript-eslint/max-params": "error",
240
+ "@typescript-eslint/member-ordering": "error",
241
+ "@typescript-eslint/method-signature-style": "error",
242
+ "@typescript-eslint/no-array-constructor": "error",
243
+ "@typescript-eslint/no-confusing-non-null-assertion": "error",
244
+ "@typescript-eslint/no-duplicate-enum-values": "error",
245
+ "@typescript-eslint/no-dynamic-delete": "error",
246
+ "@typescript-eslint/no-empty-function": "error",
247
+ "@typescript-eslint/no-empty-object-type": "error",
248
+ "@typescript-eslint/no-explicit-any": "error",
249
+ "@typescript-eslint/no-extra-non-null-assertion": "error",
250
+ "@typescript-eslint/no-extraneous-class": "error",
251
+ "@typescript-eslint/no-import-type-side-effects": "error",
252
+ "@typescript-eslint/no-inferrable-types": "error",
253
+ "@typescript-eslint/no-invalid-void-type": "error",
254
+ "@typescript-eslint/no-loop-func": "error",
255
+ "@typescript-eslint/no-magic-numbers": "off",
256
+ "@typescript-eslint/no-misused-new": "error",
257
+ "@typescript-eslint/no-namespace": "error",
258
+ "@typescript-eslint/no-non-null-asserted-nullish-coalescing": "warn",
259
+ "@typescript-eslint/no-non-null-asserted-optional-chain": "error",
260
+ "@typescript-eslint/no-non-null-assertion": "error",
261
+ "@typescript-eslint/no-redeclare": "warn",
262
+ "@typescript-eslint/no-require-imports": "error",
263
+ "@typescript-eslint/no-restricted-imports": "warn",
264
+ "@typescript-eslint/no-restricted-types": "warn",
265
+ "@typescript-eslint/no-shadow": "warn",
266
+ "@typescript-eslint/no-this-alias": "error",
267
+ "@typescript-eslint/no-unnecessary-parameter-property-assignment": "error",
268
+ "@typescript-eslint/no-unnecessary-type-constraint": "error",
269
+ "@typescript-eslint/no-unsafe-declaration-merging": "error",
270
+ "@typescript-eslint/no-unsafe-function-type": "error",
271
+ "@typescript-eslint/no-unused-expressions": "warn",
272
+ "@typescript-eslint/no-unused-private-class-members": "error",
273
+ "@typescript-eslint/no-unused-vars": "error",
274
+ "@typescript-eslint/no-use-before-define": "error",
275
+ "@typescript-eslint/no-useless-constructor": "error",
276
+ "@typescript-eslint/no-useless-empty-export": "error",
277
+ "@typescript-eslint/no-wrapper-object-types": "error",
278
+ "@typescript-eslint/prefer-as-const": "error",
279
+ "@typescript-eslint/prefer-enum-initializers": "error",
280
+ "@typescript-eslint/prefer-for-of": "error",
281
+ "@typescript-eslint/prefer-function-type": "error",
282
+ "@typescript-eslint/prefer-literal-enum-member": "error",
283
+ "@typescript-eslint/prefer-namespace-keyword": "error",
284
+ "@typescript-eslint/triple-slash-reference": "error",
285
+ "@typescript-eslint/unified-signatures": "error",
286
+ "@typescript-eslint/await-thenable": "warn",
287
+ "@typescript-eslint/consistent-return": "error",
288
+ "@typescript-eslint/consistent-type-exports": "error",
289
+ "@typescript-eslint/dot-notation": "error",
290
+ "@typescript-eslint/naming-convention": [
291
+ "warn",
292
+ {
293
+ "selector": "variable",
294
+ "format": [
295
+ "camelCase",
296
+ "UPPER_CASE",
297
+ "PascalCase"
298
+ ]
299
+ }
300
+ ],
301
+ "@typescript-eslint/no-array-delete": "error",
302
+ "@typescript-eslint/no-base-to-string": "warn",
303
+ "@typescript-eslint/no-confusing-void-expression": "error",
304
+ "@typescript-eslint/no-deprecated": "error",
305
+ "@typescript-eslint/no-duplicate-type-constituents": "error",
306
+ "@typescript-eslint/no-floating-promises": "warn",
307
+ "@typescript-eslint/no-for-in-array": "error",
308
+ "@typescript-eslint/no-implied-eval": "error",
309
+ "@typescript-eslint/no-meaningless-void-operator": "error",
310
+ "@typescript-eslint/no-misused-promises": "error",
311
+ "@typescript-eslint/no-misused-spread": "error",
312
+ "@typescript-eslint/no-mixed-enums": "error",
313
+ "@typescript-eslint/no-redundant-type-constituents": "error",
314
+ "@typescript-eslint/no-unnecessary-boolean-literal-compare": "error",
315
+ "@typescript-eslint/no-unnecessary-condition": "error",
316
+ "@typescript-eslint/no-unnecessary-qualifier": "warn",
317
+ "@typescript-eslint/no-unnecessary-template-expression": "error",
318
+ "@typescript-eslint/no-unnecessary-type-arguments": "error",
319
+ "@typescript-eslint/no-unnecessary-type-assertion": "error",
320
+ "@typescript-eslint/no-unnecessary-type-conversion": "error",
321
+ "@typescript-eslint/no-unnecessary-type-parameters": "error",
322
+ "@typescript-eslint/no-unsafe-argument": "error",
323
+ "@typescript-eslint/no-unsafe-assignment": "error",
324
+ "@typescript-eslint/no-unsafe-call": "error",
325
+ "@typescript-eslint/no-unsafe-enum-comparison": "error",
326
+ "@typescript-eslint/no-unsafe-member-access": "error",
327
+ "@typescript-eslint/no-unsafe-return": "error",
328
+ "@typescript-eslint/no-unsafe-type-assertion": "error",
329
+ "@typescript-eslint/no-unsafe-unary-minus": "warn",
330
+ "@typescript-eslint/no-useless-default-assignment": "error",
331
+ "@typescript-eslint/non-nullable-type-assertion-style": "warn",
332
+ "@typescript-eslint/only-throw-error": "error",
333
+ "@typescript-eslint/prefer-destructuring": "error",
334
+ "@typescript-eslint/prefer-find": "error",
335
+ "@typescript-eslint/prefer-includes": "error",
336
+ "@typescript-eslint/prefer-nullish-coalescing": "error",
337
+ "@typescript-eslint/prefer-optional-chain": "error",
338
+ "@typescript-eslint/prefer-promise-reject-errors": "error",
339
+ "@typescript-eslint/prefer-readonly": "error",
340
+ "@typescript-eslint/prefer-readonly-parameter-types": [
341
+ "error",
342
+ {
343
+ "ignoreInferredTypes": true
344
+ }
345
+ ],
346
+ "@typescript-eslint/prefer-reduce-type-parameter": "error",
347
+ "@typescript-eslint/prefer-regexp-exec": "warn",
348
+ "@typescript-eslint/prefer-return-this-type": "error",
349
+ "@typescript-eslint/prefer-string-starts-ends-with": "error",
350
+ "@typescript-eslint/promise-function-async": "error",
351
+ "@typescript-eslint/related-getter-setter-pairs": "error",
352
+ "@typescript-eslint/require-array-sort-compare": "error",
353
+ "@typescript-eslint/require-await": "error",
354
+ "@typescript-eslint/restrict-plus-operands": "error",
355
+ "@typescript-eslint/restrict-template-expressions": "error",
356
+ "@typescript-eslint/return-await": "error",
357
+ "@typescript-eslint/strict-boolean-expressions": "error",
358
+ "@typescript-eslint/strict-void-return": "off",
359
+ "@typescript-eslint/switch-exhaustiveness-check": "error",
360
+ "@typescript-eslint/unbound-method": "warn",
361
+ "@typescript-eslint/use-unknown-in-catch-callback-variable": "error"
362
+ },
363
+ "completedSections": [
364
+ "Core — Other",
365
+ "TypeScript",
366
+ "TypeScript — type-aware"
367
+ ],
368
+ "pausedSection": null,
369
+ "pausedAt": 0
370
+ }
package/oop/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # Lua Object Oriented Programming Class Module
2
+
3
+ Lua object oriented programming class module allow you to use oop similar to the TypeScript/JavaScript/Java/C++ Classes
4
+
5
+ ## Lua Modules Setup
6
+
7
+ Auto-configure Lua to use `./lua_modules` (like `node_modules`) instead of unorganized directories.
8
+
9
+ ### Install
10
+ - MAC
11
+ ```bash
12
+ npx mac-lua-modules
13
+ ```
14
+
15
+ ### Usage
16
+ ```bash
17
+ # Install Lua packages
18
+ luarocks install --tree ./lua_modules inspect
19
+
20
+ # Use in code (no setup needed)
21
+ local inspect = require('inspect')
22
+ print(inspect({name = "Lenix"}))
23
+ ```
24
+
25
+ ### What it does
26
+
27
+ Adds environment variables to your shell config (for mac users: `~/.zshrc` or `~/.bashrc`) to automatically change your Lua modules configurations to `./lua_modules` instead of hidden nested directories.
package/package.json CHANGED
@@ -1,20 +1,21 @@
1
1
  {
2
2
  "name": "lenix",
3
- "version": "1.3.4",
4
- "description": "The Monorepo for the software engineering community",
3
+ "version": "1.4.0",
4
+ "description": "The All-in-one Package",
5
5
  "author": "Lenix",
6
6
  "license": "GPL-3.0",
7
7
  "type": "module",
8
+ "readme": "modules/README.md",
8
9
  "keywords": [
9
10
  "lenix",
10
11
  "modules",
11
12
  "typescript",
12
13
  "lua",
13
14
  "luarocks",
15
+ "oop",
14
16
  "fivem",
15
17
  "fxmanifest",
16
18
  "api",
17
- "oop",
18
19
  "class",
19
20
  "eslint",
20
21
  "linter"
@@ -23,15 +24,15 @@
23
24
  "type": "git",
24
25
  "url": "git+https://github.com/lenixdev/lenix.git"
25
26
  },
26
- "main": "./ts/dist/index.js",
27
- "types": "./ts/dist/index.d.ts",
27
+ "main": "./modules/dist/index.js",
28
+ "types": "./modules/dist/index.d.ts",
28
29
  "bin": {
29
- "mac-lua-modules": "lua/mac-lua-modules.sh",
30
+ "mac-lua-modules": "oop/mac-lua-modules.sh",
30
31
  "lenix": "./lint/dist/lint.mjs"
31
32
  },
32
33
  "files": [
33
- "ts/dist",
34
- "lua",
34
+ "modules/dist",
35
+ "oop",
35
36
  "lint/dist"
36
37
  ],
37
38
  "dependencies": {
@@ -51,7 +52,7 @@
51
52
  "typescript": "^5.3.3"
52
53
  },
53
54
  "scripts": {
54
- "build": "tsc -p ts/src/fxmanifest/tsconfig.json && tsc-alias && tsc -p lint/src/tsconfig.json",
55
+ "build": "tsc -p modules/src/fxmanifest/tsconfig.json && tsc-alias && tsc -p lint/src/tsconfig.json",
55
56
  "bump": "pnpm version patch"
56
57
  }
57
58
  }
@@ -1,202 +0,0 @@
1
- local class<const> = function (fields)
2
- local defined<const> = {}
3
- local private<const> = fields.private or {}
4
- local getter<const> = fields.get or {}
5
- local setter<const> = fields.set or {}
6
- local accessor<const> = fields.accessor or {}
7
- local privates<const> = { static = {}, instance = {} }
8
- local setProperties<const> = { static = {}, instance = {} }
9
- local getProperties<const> = { static = {}, instance = {} }
10
-
11
- local isVariableEligible<const> = function (variable, valueType, value)
12
- if defined[variable] then
13
- print(("`%s` is already defined"):format(variable))
14
- return
15
- elseif type(value) ~= valueType and valueType ~= "any" then
16
- print(("type mismatch for `%s`, expected `%s`, got `%s`"):format(variable, valueType, type(value)))
17
- return
18
- end
19
- defined[variable] = true
20
- if valueType == "any" then
21
- print(("variable `%s` implicitly has type `%s`"):format(variable, valueType, type(value)))
22
- end
23
- return true
24
- end
25
-
26
- local fieldPairs<const> = {
27
- {private, privates},
28
- {getter, getProperties},
29
- {setter, setProperties},
30
- {accessor, nil}
31
- }
32
-
33
- for _, pair in ipairs(fieldPairs) do
34
- local source, target = pair[1], pair[2]
35
- for variable, values in pairs(source) do
36
- -- getPropertyValue
37
- local value<const> = type(values) == "table" and values[1]
38
- -- getPropertyType
39
- local valueType<const> = type(values) == "table" and values[2] or "any"
40
- local staticValue<const> = values and values[3] or false
41
- if isVariableEligible(variable, valueType, value) then
42
- -- fill table with keys and values
43
- if target then
44
- if staticValue then
45
- target["static"][variable] = value
46
- else
47
- target["instance"][variable] = value
48
- end
49
- else
50
- if staticValue then
51
- getProperties["static"][variable] = value
52
- setProperties["static"][variable] = value
53
- else
54
- getProperties["instance"][variable] = value
55
- setProperties["instance"][variable] = value
56
- end
57
- end
58
- end
59
- end
60
- end
61
-
62
- return setmetatable({
63
- new = function (self, ...)
64
- local newInstanceArgs = {...}
65
- print(self)
66
- local constructor<const> = fields.constructor
67
- constructor(self, nil, ...)
68
- return setmetatable({}, {
69
- __index = function (_, variableKey)
70
- if getter["instance"][variableKey] then
71
- return getProperties["instance"][variableKey]
72
- elseif accessor["instance"][variableKey] then
73
- return getProperties["instance"][variableKey]
74
- end
75
- end,
76
- })
77
- end
78
- }, {
79
- __index = function(_, variableKey)
80
- assert(defined[variableKey], ("property `%s` not found"):format(variableKey))
81
- -- isPropertyExist
82
- if getter[variableKey] ~= nil then
83
- if isStatic(getter, variableKey, "get") then
84
- -- returnPropertyValue
85
- return getProperties["static"][variableKey]
86
- end
87
- elseif accessor[variableKey] ~= nil then
88
- if isStatic(accessor, variableKey, "accessor") then
89
- return getProperties["static"][variableKey]
90
- end
91
- elseif private[variableKey] ~= nil then
92
- print(("cannot read the private property `%s`"):format(variableKey))
93
- elseif setter[variableKey] ~= nil then
94
- print(("the setter only property `%s` can not be accessed"):format(variableKey))
95
- else print(("something went wrong when trying to access `%s`"):format(variableKey)) end
96
- end,
97
- __newindex = function (_, variableKey, variableValue)
98
- assert(defined[variableKey], ("property `%s` not found"):format(variableKey))
99
- if setter[variableKey] ~= nil then
100
- if not isStatic(setter, variableKey, "set") then
101
- local valueType = setter[variableKey][2] or "any"
102
- if type(variableValue) ~= valueType and valueType ~= "any" then
103
- print(("cannot assign `%s` to `%s` on `%s`"):format(type(variableValue), valueType, variableKey))
104
- return
105
- end
106
- end
107
- getProperties["static"][variableKey] = variableValue
108
- elseif accessor[variableKey] ~= nil then
109
- if not isStatic(accessor, variableKey, "accessor") then
110
- local valueType = accessor[variableKey][2] or "any"
111
- if type(variableValue) ~= valueType and valueType ~= "any" then
112
- print(("cannot assign `%s` to `%s` on `%s`"):format(type(variableValue), valueType, variableKey))
113
- return
114
- end
115
- end
116
- getProperties["static"][variableKey] = variableValue
117
- elseif getter[variableKey] ~= nil then
118
- print(("the getter only property `%s `can not be set"):format(variableKey))
119
- else print(("something went wrong when trying to access `%s`"):format(variableKey)) end
120
- end
121
- })
122
- end
123
-
124
- myClass = class({
125
- private = {
126
- height = {197, "number"},
127
- },
128
- get = {
129
- blood = {"O+", "any"},
130
- },
131
- set = {
132
- date = {2005, "number"},
133
- },
134
- accessor = {
135
- age = {20, "number"},
136
- name = {"Lenix", "string"},
137
- getBlood = {function(self) return self end, "function"}
138
- },
139
- constructor = function(self, super, name, age)
140
- self.name = name
141
- self.age = age
142
- end
143
- })
144
-
145
-
146
- local Person = myClass:new("Dev", 21)
147
- print(Person.name, Person.age)
148
- -- Person.date = 2005
149
- -- print(Person.date)
150
- -- print(Person.age)
151
- -- Person.age = 21
152
-
153
- -- print(myClass.height)
154
- -- print(myClass.blood)
155
- -- myClass.date = 2026
156
- -- print(myClass.age)
157
- -- myClass.age = 21
158
- -- print(myClass.age)
159
- -- print(myClass.name)
160
- -- myClass.name = "Dev"
161
- -- print(myClass.name)
162
- -- print(myClass.getBlood())
163
- -- myClass.getBlood = function() return true end
164
- -- print(myClass.getBlood())
165
-
166
-
167
-
168
-
169
- __index = function(_, variableKey)
170
- assert(defined[variableKey], ("property `%s` not found"):format(variableKey))
171
- -- isPropertyExist
172
- if getter[variableKey] ~= nil then
173
- -- returnPropertyValue
174
- return getProperties[variableKey]
175
- elseif accessor[variableKey] ~= nil then
176
- return getProperties[variableKey]
177
- elseif private[variableKey] ~= nil then
178
- print(("cannot read the private property `%s`"):format(variableKey))
179
- elseif setter[variableKey] ~= nil then
180
- print(("the setter only property `%s` are forbidden to be accessed"):format(variableKey))
181
- else print(("something went wrong when trying to access `%s`"):format(variableKey)) end
182
- end,
183
- __newindex = function (_, variableKey, variableValue)
184
- assert(defined[variableKey], ("property `%s` not found"):format(variableKey))
185
- if setter[variableKey] ~= nil then
186
- local valueType = setter[variableKey][2] or "any"
187
- if type(variableValue) ~= valueType and valueType ~= "any" then
188
- print(("cannot assign `%s` to `%s` on `%s`"):format(type(variableValue), valueType, variableKey))
189
- return
190
- end
191
- getProperties[variableKey] = variableValue
192
- elseif accessor[variableKey] ~= nil then
193
- local valueType = accessor[variableKey][2] or "any"
194
- if type(variableValue) ~= valueType and valueType ~= "any" then
195
- print(("cannot assign `%s` to `%s` on `%s`"):format(type(variableValue), valueType, variableKey))
196
- return
197
- end
198
- getProperties[variableKey] = variableValue
199
- elseif getter[variableKey] ~= nil then
200
- print(("the getter only property `%s `can not be set"):format(variableKey))
201
- else print(("something went wrong when trying to access `%s`"):format(variableKey)) end
202
- end