Idris2/samples/FFI-readline/readline_glue/idris_readline.c
Edwin Brady 4f10bfcfd2 Copy samples directory from Idris2-boot
This is referred to in the documentation, so should be there
2020-06-30 10:51:09 +01:00

39 lines
743 B
C

#include <readline/readline.h>
#include <string.h>
#include <stdlib.h>
rl_compentry_func_t* my_compentry;
char* compentry_wrapper(const char* text, int i) {
char* res = my_compentry(text, i); // Idris frees this
if (res != NULL) {
char* comp = malloc(strlen(res)+1); // Readline frees this
strcpy(comp, res);
return comp;
}
else {
return NULL;
}
}
void idrisrl_setCompletion(rl_compentry_func_t* fn) {
rl_completion_entry_function = compentry_wrapper;
my_compentry = fn;
}
char* getString(void* str) {
return (char*)str;
}
void* mkString(char* str) {
return (void*)str;
}
void* nullString() {
return NULL;
}
int isNullString(void* str) {
return str == NULL;
}