window_size_title_api #61
|
@ -397,6 +397,7 @@ def gen_all_bindings():
|
|||
)
|
||||
|
||||
bindgen("core", "src/wasmbind/core_api.json",
|
||||
guest_stubs="src/wasmbind/core_api_stubs.c",
|
||||
wasm3_bindings="src/wasmbind/core_api_bind_gen.c",
|
||||
)
|
||||
|
||||
|
|
|
@ -405,7 +405,7 @@ ORCA_API int oc_directory_create(oc_str8 path);
|
|||
|
||||
void ORCA_IMPORT(oc_request_quit)(void);
|
||||
|
||||
void ORCA_IMPORT(oc_runtime_window_set_title)(const char* title);
|
||||
void ORCA_IMPORT(oc_runtime_window_set_title)(oc_str8 title);
|
||||
|
||||
void ORCA_IMPORT(oc_runtime_window_set_size)(f32 width, f32 height);
|
||||
|
||||
|
|
|
@ -96,6 +96,7 @@
|
|||
//NOTE: macos application layer and graphics backends are defined in orca.m
|
||||
#elif OC_PLATFORM_ORCA
|
||||
#include "app/orca_app.c"
|
||||
#include "wasmbind/core_api_stubs.c"
|
||||
#include "graphics/graphics_common.c"
|
||||
#include "graphics/orca_surface_stubs.c"
|
||||
#else
|
||||
|
|
|
@ -66,9 +66,30 @@ oc_runtime_env* oc_runtime_env_get()
|
|||
return (&__orcaApp.runtime);
|
||||
}
|
||||
|
||||
void oc_runtime_window_set_title(const char* title)
|
||||
void* oc_runtime_ptr_to_native(oc_runtime* orca, void* wasmPtr, u32 length)
|
||||
{
|
||||
oc_window_set_title(__orcaApp.window, OC_STR8(title));
|
||||
// We can't use the runtime's memory pointer directly because wasm3 embeds a
|
||||
// header at the beginning of the block we give it.
|
||||
u64 bufferIndex = (u64)wasmPtr & 0xffffffff;
|
||||
u32 memSize = 0;
|
||||
char* memory = (char*)m3_GetMemory(orca->runtime.m3Runtime, &memSize, 0);
|
||||
|
||||
if(bufferIndex + length < memSize)
|
||||
{
|
||||
char* nativePtr = memory + bufferIndex;
|
||||
return nativePtr;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void oc_runtime_window_set_title(oc_str8 title)
|
||||
{
|
||||
title.ptr = oc_runtime_ptr_to_native(oc_runtime_get(), title.ptr, title.len);
|
||||
if(title.ptr)
|
||||
{
|
||||
oc_window_set_title(__orcaApp.window, title);
|
||||
}
|
||||
}
|
||||
|
||||
void oc_runtime_window_set_size(f32 width, f32 height)
|
||||
|
|
|
@ -125,4 +125,6 @@ typedef struct oc_runtime
|
|||
oc_runtime* oc_runtime_get();
|
||||
oc_runtime_env* oc_runtime_env_get();
|
||||
|
||||
void* oc_runtime_ptr_to_native(oc_runtime* runtime, void* wasmPtr, u32 length);
|
||||
|
||||
#endif //__RUNTIME_H_
|
||||
|
|
|
@ -14,19 +14,12 @@ oc_io_cmp oc_runtime_io_wait_single_req(oc_io_req* wasmReq)
|
|||
|
||||
oc_io_cmp cmp = { 0 };
|
||||
oc_io_req req = *wasmReq;
|
||||
//NOTE: convert the req->buffer wasm pointer to a native pointer
|
||||
// for some reason, wasm3 memory doesn't start at the beginning of the block we give it.
|
||||
u64 bufferIndex = (u64)req.buffer & 0xffffffff;
|
||||
u32 memSize = 0;
|
||||
char* memory = (char*)m3_GetMemory(orca->runtime.m3Runtime, &memSize, 0);
|
||||
|
||||
if(bufferIndex + req.size > memSize)
|
||||
void* buffer = oc_runtime_ptr_to_native(orca, req.buffer, req.size);
|
||||
|
||||
if(buffer)
|
||||
{
|
||||
cmp.error = OC_IO_ERR_ARG;
|
||||
}
|
||||
else
|
||||
{
|
||||
req.buffer = memory + bufferIndex;
|
||||
req.buffer = buffer;
|
||||
|
||||
if(req.op == OC_IO_OPEN_AT)
|
||||
{
|
||||
|
@ -39,5 +32,10 @@ oc_io_cmp oc_runtime_io_wait_single_req(oc_io_req* wasmReq)
|
|||
}
|
||||
cmp = oc_io_wait_single_req_with_table(&req, &orca->fileTable);
|
||||
}
|
||||
else
|
||||
{
|
||||
cmp.error = OC_IO_ERR_ARG;
|
||||
}
|
||||
|
||||
return (cmp);
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@
|
|||
"ret": {"name": "void", "tag": "v"},
|
||||
"args": [
|
||||
{ "name": "title",
|
||||
"type": {"name": "const char*", "tag": "p"}}
|
||||
"type": {"name": "oc_str8", "tag": "S"}}
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue