fix(trixy/examples/main): Improve c code
This commit is contained in:
parent
d904a19f48
commit
5ce46a1568
|
@ -26,18 +26,18 @@
|
|||
#include <string.h>
|
||||
|
||||
#define println(args...) \
|
||||
printf ("[32;1m(plugin):[0m [34;1m"); \
|
||||
printf ("\33[32;1m(plugin):\33[0m \33[34;1m"); \
|
||||
printf (args); \
|
||||
printf ("\n[0m"); \
|
||||
printf ("\n\33[0m"); \
|
||||
fflush (stdout);
|
||||
#define eprintln(args...) \
|
||||
printf ("[32;1m(plugin):[0m[31;1m "); \
|
||||
printf ("\33[32;1m(plugin):\33[0m\33[31;1m "); \
|
||||
printf (args); \
|
||||
printf ("\n[0m"); \
|
||||
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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Reference in New Issue