aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/ffi.jl14
-rw-r--r--examples/ffi.py10
2 files changed, 19 insertions, 5 deletions
diff --git a/examples/ffi.jl b/examples/ffi.jl
new file mode 100644
index 0000000..b92a52d
--- /dev/null
+++ b/examples/ffi.jl
@@ -0,0 +1,14 @@
+c_status = ccall((:status, "target/debug/senpy_ffi"), Int32, ())
+status = ""
+
+if c_status == 1
+ status = "up"
+elseif c_status == 0
+ status = "down"
+elseif c_status == -1
+ status = "not down, but unreachable"
+else
+ status = "unknown"
+end
+
+print("status: api.senpy.club is ", status)
diff --git a/examples/ffi.py b/examples/ffi.py
index 19cc1ac..1b2b798 100644
--- a/examples/ffi.py
+++ b/examples/ffi.py
@@ -7,16 +7,16 @@ extension: str = {"darwin": ".dylib", "win32": ".dll"}.get(sys.platform, ".so")
ffi = FFI()
ffi.cdef(
"""
- typedef struct { char *language; char *image; } random_t;
+ struct Random { char *language; char *image; };
char **language(const char *);
char **languages(void);
- random_t *random_new(void);
- void random_populate(random_t *);
- void random_free(random_t *);
- char *random_get(const random_t *, const char *);
+ struct Random *random_new(void);
+ void random_populate(struct Random *);
+ void random_free(struct Random *);
+ char *random_get(const struct Random *, const char *);
int status(void);
"""