Skip to content

Commit

Permalink
feat: add SetString and String ffi
Browse files Browse the repository at this point in the history
  • Loading branch information
wobsoriano committed Sep 16, 2023
1 parent f25dd6a commit 37a8d32
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
6 changes: 0 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ func Render(keyPtr *C.char, text *C.char) *C.char {
return ch(m[key].Render(str(text)))
}

//export SetString
func SetString(keyPtr *C.char, text *C.char) {
key := str(keyPtr)
m[key].SetString(str(text))
}

//export String
func String(keyPtr *C.char) *C.char {
key := str(keyPtr)
Expand Down
4 changes: 4 additions & 0 deletions src/ffi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export const { symbols } = dlopen(location, {
args: [FFIType.ptr, FFIType.ptr],
returns: FFIType.ptr
},
String: {
args: [FFIType.ptr],
returns: FFIType.ptr
},
Copy: {
args: [FFIType.ptr],
returns: FFIType.ptr
Expand Down
11 changes: 11 additions & 0 deletions src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ export class Style {
return this
}

SetString(text: string) {
return this.SetStringValue('SetString', text)
}

String() {
const textPtr = symbols.String(this.#handle)
const textStr = new CString(textPtr!)
symbols.FreeString(textStr.ptr)
return textStr.toString()
}

Bold(val: boolean) {
return this.SetBooleanValue('Bold', val)
}
Expand Down

0 comments on commit 37a8d32

Please sign in to comment.