-
Notifications
You must be signed in to change notification settings - Fork 150
Closes #274: Adding FFI function for types bool, float, String, vecbytes #903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 14 commits
a868f66
4034bab
78cca4b
8a16031
6713bfd
42d5196
0336c2c
8729967
2d24b1f
ceb86ca
3534df1
b5f1c60
7d89c8a
39f706a
95fad0a
8c8cf0f
3c755f3
a8eb625
0def6c6
5e0458a
f109f17
2288743
8101f97
0ff0a45
1859521
7aa84bd
1276f50
a9e639c
d78201f
6a1921b
c21de21
2076d94
5412afc
f4739f7
d3762fd
2e9db51
7c4158f
69920f2
4b7a919
0cdd885
fe30b78
a835c83
58086e6
7eb6792
fe938dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,7 +65,7 @@ jobs: | |
steps: | ||
- uses: actions/checkout@v5 | ||
- name: Spell Check Repo | ||
uses: crate-ci/[email protected].2 | ||
uses: crate-ci/[email protected].3 | ||
|
||
license-headers: | ||
name: check license headers | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -256,6 +256,24 @@ int guest_function(const char *from_host) { | |
return 0; | ||
} | ||
|
||
|
||
bool host_returns_bool_value(const char *from_host) { | ||
char guest_message[256] = "Hello from host_returns_bool_value, "; | ||
int len = strlen(from_host); | ||
strncat(guest_message, from_host, len); | ||
|
||
hl_Parameter params = {.tag = hl_ParameterType_Bool, | ||
.value = {.Bool = true}}; | ||
const hl_FunctionCall host_call = {.function_name = "HostMethod1", | ||
.parameters = ¶ms, | ||
.parameters_len = 1, | ||
.return_type = hl_ReturnType_Bool | ||
}; | ||
hl_call_host_function(&host_call); | ||
return hl_get_host_return_value_as_Bool(); | ||
} | ||
|
||
HYPERLIGHT_WRAP_FUNCTION(host_returns_bool_value, Bool, 1, String) | ||
HYPERLIGHT_WRAP_FUNCTION(echo, String, 1, String) | ||
// HYPERLIGHT_WRAP_FUNCTION(set_byte_array_to_zero, 1, VecBytes) is not valid for functions that return VecBytes | ||
HYPERLIGHT_WRAP_FUNCTION(guest_function, Int, 1, String) | ||
|
@@ -289,6 +307,7 @@ HYPERLIGHT_WRAP_FUNCTION(log_message, Int, 2, String, Long) | |
|
||
void hyperlight_main(void) | ||
{ | ||
HYPERLIGHT_REGISTER_FUNCTION("HostReturnsBoolValue", host_returns_bool_value); | ||
HYPERLIGHT_REGISTER_FUNCTION("Echo", echo); | ||
// HYPERLIGHT_REGISTER_FUNCTION macro does not work for functions that return VecBytes, | ||
// so we use hl_register_function_definition directly | ||
|
@@ -325,6 +344,9 @@ void hyperlight_main(void) | |
// HYPERLIGHT_REGISTER_FUNCTION macro does not work for functions that return VecBytes, | ||
// so we use hl_register_function_definition directly | ||
hl_register_function_definition("24K_in_8K_out", twenty_four_k_in_eight_k_out, 1, (hl_ParameterType[]){hl_ParameterType_VecBytes}, hl_ReturnType_VecBytes); | ||
// HYPERLIGHT_REGISTER_FUNCTION macro does not work for functions that return VecBytes, | ||
// so we use hl_register_function_definition directly | ||
hl_register_function_definition("24K_in_8K_out", twenty_four_k_in_eight_k_out, 1, (hl_ParameterType[]){hl_ParameterType_VecBytes}, hl_ReturnType_VecBytes); | ||
|
||
} | ||
|
||
// This dispatch function is only used when the host dispatches a guest function | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not taking a string as parameter might make this simpler to test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you I will look at doing it without string input.