fix(trixy/examples/main): Improve c code

This commit is contained in:
Benedikt Peetz 2024-02-19 20:58:21 +01:00
parent d904a19f48
commit 5ce46a1568
Signed by: bpeetz
GPG Key ID: A5E94010C3A642AD
2 changed files with 8 additions and 8 deletions

View File

@ -26,18 +26,18 @@
#include <string.h>
#define println(args...) \
printf ("(plugin): "); \
printf ("\33[32;1m(plugin):\33[0m \33[34;1m"); \
printf (args); \
printf ("\n"); \
printf ("\n\33[0m"); \
fflush (stdout);
#define eprintln(args...) \
printf ("(plugin): "); \
printf ("\33[32;1m(plugin):\33[0m\33[31;1m "); \
printf (args); \
printf ("\n"); \
printf ("\n\33[0m"); \
fflush (stdout);
int
p_main ()
plugin_main ()
{
// You can simply call functions ..
outstanding ("James");
@ -47,7 +47,7 @@ p_main ()
//
// A error will be signaled by a 0 return code, then the error can be
// obtained with the `last_error_length` and `last_error_message` functions
if (!outstanding (0x0))
if (!outstanding (NULL))
{
int error_length = last_error_length ();
char *error = malloc (error_length);

View File

@ -49,11 +49,11 @@ fn handle_cmd(cmd: Commands) {
fn main() {
let library_path = env::args().nth(1).expect("USAGE: cargo r -- <LIB>");
type AddFunc = unsafe fn() -> c_int;
println!("Loading p_main() from {}", library_path);
println!("Loading plugin_main() from {}", library_path);
unsafe {
let lib = Library::new(library_path).unwrap();
let func: Symbol<AddFunc> = lib.get(b"p_main").unwrap();
let func: Symbol<AddFunc> = lib.get(b"plugin_main").unwrap();
println!("starting plugin");
let out = func();
println!("plugin finished with: {}", out);