mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 07:08:48 +00:00
Remove pointer magic when creating strings
This commit is contained in:
Vendored
+4
-7
@@ -1,8 +1,6 @@
|
|||||||
//+build js wasm32, js wasm64p32
|
//+build js wasm32, js wasm64p32
|
||||||
package wasm_js_interface
|
package wasm_js_interface
|
||||||
|
|
||||||
import "core:runtime"
|
|
||||||
|
|
||||||
foreign import dom_lib "odin_dom"
|
foreign import dom_lib "odin_dom"
|
||||||
|
|
||||||
Event_Kind :: enum u32 {
|
Event_Kind :: enum u32 {
|
||||||
@@ -235,6 +233,8 @@ Event :: struct {
|
|||||||
|
|
||||||
repeat: bool,
|
repeat: bool,
|
||||||
|
|
||||||
|
_key_len: int,
|
||||||
|
_code_len: int,
|
||||||
_key_buf: [KEYBOARD_MAX_KEY_SIZE]byte,
|
_key_buf: [KEYBOARD_MAX_KEY_SIZE]byte,
|
||||||
_code_buf: [KEYBOARD_MAX_KEY_SIZE]byte,
|
_code_buf: [KEYBOARD_MAX_KEY_SIZE]byte,
|
||||||
},
|
},
|
||||||
@@ -350,11 +350,8 @@ do_event_callback :: proc(user_data: rawptr, callback: proc(e: Event)) {
|
|||||||
init_event_raw(&event)
|
init_event_raw(&event)
|
||||||
|
|
||||||
if event.kind == .Key_Up || event.kind == .Key_Down || event.kind == .Key_Press {
|
if event.kind == .Key_Up || event.kind == .Key_Down || event.kind == .Key_Press {
|
||||||
key := transmute(^runtime.Raw_String) &event.key.key
|
event.key.key = string(event.key._key_buf[:event.key._key_len])
|
||||||
key.data = &event.key._key_buf[0]
|
event.key.code = string(event.key._code_buf[:event.key._code_len])
|
||||||
|
|
||||||
code := transmute(^runtime.Raw_String) &event.key.code
|
|
||||||
code.data = &event.key._code_buf[0]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(event)
|
callback(event)
|
||||||
|
|||||||
Vendored
+7
-7
@@ -1423,13 +1423,11 @@ function odinSetupDefaultImports(wasmMemoryInterface, consoleElement) {
|
|||||||
wmi.storeI16(off(2), e.button);
|
wmi.storeI16(off(2), e.button);
|
||||||
wmi.storeU16(off(2), e.buttons);
|
wmi.storeU16(off(2), e.buttons);
|
||||||
} else if (e instanceof KeyboardEvent) {
|
} else if (e instanceof KeyboardEvent) {
|
||||||
// NOTE: we set string data pointers on the
|
// Note: those strigs are constructed
|
||||||
// native side, so skip those for now and
|
// on the native side from buffers that
|
||||||
// set only string length
|
// are filled later, so skip them
|
||||||
const keyPtr = off(W);
|
const keyPtr = off(W*2, W);
|
||||||
wmi.storeI32(off(W), e.key.length);
|
const codePtr = off(W*2, W);
|
||||||
const codePtr = off(W);
|
|
||||||
wmi.storeI32(off(W), e.code.length);
|
|
||||||
|
|
||||||
wmi.storeU8(off(1), e.location);
|
wmi.storeU8(off(1), e.location);
|
||||||
|
|
||||||
@@ -1440,6 +1438,8 @@ function odinSetupDefaultImports(wasmMemoryInterface, consoleElement) {
|
|||||||
|
|
||||||
wmi.storeU8(off(1), !!e.repeat);
|
wmi.storeU8(off(1), !!e.repeat);
|
||||||
|
|
||||||
|
wmi.storeI32(off(W), e.key.length)
|
||||||
|
wmi.storeI32(off(W), e.code.length)
|
||||||
wmi.storeString(off(16, 1), e.key);
|
wmi.storeString(off(16, 1), e.key);
|
||||||
wmi.storeString(off(16, 1), e.code);
|
wmi.storeString(off(16, 1), e.code);
|
||||||
} else if (e instanceof WheelEvent) {
|
} else if (e instanceof WheelEvent) {
|
||||||
|
|||||||
Reference in New Issue
Block a user