Skip to content

Commit 667bf09

Browse files
committed
some fix
1 parent 794b763 commit 667bf09

4 files changed

Lines changed: 152 additions & 73 deletions

File tree

examples/call_zig_from_js/main.zig

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ const html = @embedFile("index.html");
88
pub fn main() !void {
99
var nwin = try webui.newWindow();
1010

11-
_ = try nwin.bind("my_function_string", my_function_string);
12-
_ = try nwin.bind("my_function_integer", my_function_integer);
11+
_ = try nwin.binding("my_function_string", getString);
12+
// _ = try nwin.bind("my_function_string", my_function_string);
13+
_ = try nwin.binding("my_function_integer", getInteger);
14+
// _ = try nwin.bind("my_function_integer", my_function_integer);
1315
_ = try nwin.bind("my_function_boolean", my_function_boolean);
1416
_ = try nwin.bind("my_function_with_response", my_function_with_response);
1517
_ = try nwin.bind("my_function_raw_binary", my_function_raw_binary);
@@ -21,6 +23,13 @@ pub fn main() !void {
2123
webui.clean();
2224
}
2325

26+
fn getString(str1: [:0]const u8, str2: [:0]const u8) void {
27+
// Hello
28+
std.debug.print("my_function_string 1: {s}\n", .{str1});
29+
// World
30+
std.debug.print("my_function_string 2: {s}\n", .{str2});
31+
}
32+
2433
fn my_function_string(e: *webui.Event) void {
2534
// JavaScript:
2635
// my_function_string('Hello', 'World`);
@@ -35,6 +44,12 @@ fn my_function_string(e: *webui.Event) void {
3544
std.debug.print("my_function_string 2: {s}\n", .{str_2});
3645
}
3746

47+
fn getInteger(n1: i64, n2: i64, n3: i64, f1: f64) void {
48+
std.debug.print("number is {},{},{},{}", .{
49+
n1, n2, n3, f1,
50+
});
51+
}
52+
3853
fn my_function_integer(e: *webui.Event) void {
3954
// JavaScript:
4055
// my_function_integer(123, 456, 789, 12345.6789);
@@ -95,7 +110,7 @@ fn my_function_raw_binary(e: *webui.Event) void {
95110

96111
// Or e.getStringAt(0);
97112
const raw_1 = e.getString();
98-
const raw_2 = e.getStringAt(1);
113+
const raw_2 = e.getRawAt(1);
99114

100115
// Or e.getSizeAt(0);
101116
const len_1 = e.getSize() catch return;

examples/custom_spa_server_on_free_port/main.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! Custom web Server - Free Port - Example
2+
// Note: if you want to run this example, you nedd a python, zig will wrap a child process to launch python server
23
const std = @import("std");
34
const webui = @import("webui");
45

src/c.zig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,16 @@ pub extern fn webui_return_string(e: *Event, s: [*:0]const u8) callconv(.C) void
895895
/// @example webui_return_bool(e, true);
896896
pub extern fn webui_return_bool(e: *Event, b: bool) callconv(.C) void;
897897

898+
/// @brief Get the last WebUI error code.
899+
///
900+
/// @example int error_num = webui_get_last_error_number();
901+
pub extern fn webui_get_last_error_number() callconv(.C) c_int;
902+
903+
/// @brief Get the last WebUI error message.
904+
///
905+
/// @example const char* error_msg = webui_get_last_error_message();
906+
pub extern fn webui_get_last_error_message() callconv(.C) [*:0]const u8;
907+
898908
// -- Wrapper's Interface -------------
899909

900910
/// @brief Bind a specific HTML element click event with a function. Empty element means all events.

0 commit comments

Comments
 (0)