Skip to content

Commit

Permalink
attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
rhazarian committed Mar 21, 2024
1 parent 8717dbb commit ee2345e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/attributes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export type Attribute<T> = {
readonly __attribute: unique symbol
readonly __type: T
} & symbol

export namespace Attribute {
export const create = <T>(): Attribute<T> => {
return {} as Attribute<T>
}
}

export class AttributesHolder {
declare readonly get: (<T>(attribute: Attribute<T>) => T | undefined) &
LuaExtension<"TableGetMethod">
declare readonly set: (<T>(attribute: Attribute<T>, value: T | undefined) => void) &
LuaExtension<"TableSetMethod">
}
4 changes: 4 additions & 0 deletions src/core/types/handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Event } from "../../event"
import { getClass, getSuperclass } from "../../utility/reflection"
import { AbstractConstructor } from "../../utility/types"
import { IllegalStateException } from "../../exception"
import { AttributesHolder } from "../../attributes"

const getHandleId = GetHandleId

Expand Down Expand Up @@ -40,6 +41,7 @@ const enum HandlePropertyKey {
}

export class Handle<H extends jhandle, DestroyParameters extends any[] = []>
extends AttributesHolder
implements Destroyable
{
public readonly handle: H
Expand All @@ -53,6 +55,8 @@ export class Handle<H extends jhandle, DestroyParameters extends any[] = []>
* The constructor is public solely for type inference purposes.
*/
public constructor(handle: H) {
super()

this[HandlePropertyKey.STATE] = HandleState.BEING_CREATED

const id = getHandleId(handle)
Expand Down

0 comments on commit ee2345e

Please sign in to comment.