Skip to content

Instantly share code, notes, and snippets.

Brandon Fish bjfish

Block or report user

Report or block bjfish

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:5418c723e27b68183dd13c4316d519fc
ActionController::RoutingError (uninitialized constant ApplicationController):
app/controllers/welcome_controller.rb:2:in `<top (required)>'
ActionController::RoutingError: uninitialized constant ApplicationController
from /Users/bfish/Documents/railstest/skip_active_record/app/controllers/welcome_controller.rb:2:in `<top (required)>'
from /Users/bfish/Documents/gem_homes/nokogiri_gem_home/gems/activesupport-4.2.9/lib/active_support/inflector/methods.rb:261:in `const_get'
from /Users/bfish/Documents/gem_homes/nokogiri_gem_home/gems/activesupport-4.2.9/lib/active_support/inflector/methods.rb:261:in `block in constantize'
View wasmer-c-api-5.c
// Create module name for our imports
// represented in bytes for UTF-8 compatability
char *module_name = "env";
wasmer_byte_array module_name_bytes;
module_name_bytes.bytes = module_name;
module_name_bytes.bytes_len = strlen(module_name);
// Define a function import
char *import_name = "_print_str";
wasmer_byte_array import_name_bytes;
View wasmer-c-api-8.c
// Call the exported "hello_wasm" function of our instance
wasmer_value_t params[] = {};
wasmer_value_t result_one;
wasmer_value_t results[] = {result_one};
wasmer_result_t call_result = wasmer_instance_call(instance, "_hello_wasm", params, 0, results, 1);
printf("Call result: %d\n", call_result);
assert(call_result == WASMER_OK);
assert(print_str_called);
// Use *_destroy methods to cleanup as specified in the header documentation
View wasmer-c-api-7.c
// Call the exported "hello_wasm" function of our instance
wasmer_value_t params[] = {};
wasmer_value_t result_one;
wasmer_value_t results[] = {result_one};
wasmer_result_t call_result = wasmer_instance_call(instance, "_hello_wasm", params, 0, results, 1);
printf("Call result: %d\n", call_result);
assert(call_result == WASMER_OK);
assert(print_str_called);
// Use *_destroy methods to cleanup as specified in the header documentation
View wasmer-c-api-6.c
// Read the wasm file bytes
FILE *file = fopen("wasm-sample-app/target.wasm", "r");
fseek(file, 0, SEEK_END);
long len = ftell(file);
uint8_t *bytes = malloc(len);
fseek(file, 0, SEEK_SET);
fread(bytes, 1, len, file);
fclose(file);
// Creates a WebAssembly Instance from wasm bytes and imports
View wasmer-c-api-4.c
int main()
{
wasmer_value_tag params_sig[] = {WASM_I32, WASM_I32};
wasmer_value_tag returns_sig[] = {};
wasmer_import_func_t *func = wasmer_import_func_new(print_str, params_sig, 2, returns_sig, 0);
View wasmer-c-api-3.c
void print_wasmer_error()
{
int error_len = wasmer_last_error_length();
printf("Error len: `%d`\n", error_len);
char *error_str = malloc(error_len);
wasmer_last_error_message(error_str, error_len);
printf("Error str: `%s`\n", error_str);
}
View wasmer-c-api-2.c
void print_str(wasmer_instance_context_t *ctx, int32_t ptr, int32_t len)
{
print_str_called = true;
wasmer_memory_t *memory = wasmer_instance_context_memory(ctx, 0);
uint32_t mem_len = wasmer_memory_length(memory);
uint8_t *mem_bytes = wasmer_memory_data(memory);
printf("%.*s", len, mem_bytes + ptr);
}
@bjfish
bjfish / source.c
Created Mar 3, 2019
Hello World C Wasm Example App
View source.c
extern void print_str(char *ptr, int len);
int hello_wasm()
{
char *str = "Hello, World!";
print_str(str, 13);
return 0;
}
You can’t perform that action at this time.