diff options
Diffstat (limited to 'c/defs.h')
-rw-r--r-- | c/defs.h | 52 |
1 files changed, 49 insertions, 3 deletions
@@ -66,9 +66,55 @@ struct DataListView : public ListView }; /* pl.cpp */ -int Pl(const char *, const char *, const char *, ...); -int Plp(term_t, const char *, ...); -int Plg(term_t, const char *, ...); +int Pl(const char *, const char *); + +inline int PlPut(term_t t, int x) { return PL_put_integer(t, x); } +inline int PlPut(term_t t, long x) { return PL_put_integer(t, x); } +inline int PlPut(term_t t, long long x) { return PL_put_integer(t, x); } +inline int PlPut(term_t t, atom_t x) { return PL_put_atom(t, x); } +inline int PlPut(term_t t, char *x) { return PL_put_atom(t, PL_new_atom(x)); } +inline int PlPut(term_t t, const char *x) { return PL_put_atom(t, PL_new_atom(x)); } +inline int PlPut(term_t t, int *x) { return -1; } +inline int PlPut(term_t t, long *x) { return -1; } +inline int PlPut(term_t t, long long *x) { return -1; } +inline int PlPut(term_t t, atom_t *x) { return -1; } +inline int PlPut(term_t t, char **x) { return -1; } + +inline int PlGet(term_t t, int x) { return -1; } +inline int PlGet(term_t t, long x) { return -1; } +inline int PlGet(term_t t, long long x) { return -1; } +inline int PlGet(term_t t, atom_t x) { return -1; } +inline int PlGet(term_t t, char *x) { return -1; } +inline int PlGet(term_t t, const char *x) { return -1; } +inline int PlGet(term_t t, int *x) { return PL_get_integer(t, x); } +inline int PlGet(term_t t, long *x) { return PL_get_long(t, x); } +inline int PlGet(term_t t, long long *x) { return PL_get_int64(t, x); } +inline int PlGet(term_t t, atom_t *x) { return PL_get_atom(t, x); } +inline int PlGet(term_t t, char **x) { return PL_get_atom_chars(t, x); } + +template <typename T> +int PlPutv(term_t t, T arg) { return PlPut(t, arg); } +template <typename T, typename ...R> +int PlPutv(term_t t, T arg, R... rest) { return PlPut(t, arg)? PlPutv(t+1, rest...): 0; } +template <typename T> +int PlGetv(term_t t, T arg) { return PlGet(t, arg); } +template <typename T, typename ...R> +int PlGetv(term_t t, T arg, R... rest) { return PlGet(t, arg)? PlGetv(t+1, rest...): 0; } +template <typename T> +int Countv(int i, T arg) { return i+1; } +template <typename T, typename ...R> +int Countv(int i, T arg, R... rest) { return Countv(i+1, rest...); } +template <typename ...T> +int Pl(const char *szMod, const char *szPred, T... args) +{ + int iArity = Countv(0, args...); + term_t t = PL_new_term_refs(iArity); + if (!PlPutv(t, args...)) return 0; + if (!PL_call_predicate(NULL, PL_Q_NORMAL, PL_predicate(szPred, iArity, szMod), t)) + return 0; + if (!PlGetv(t, args...)) return 0; + return 1; +} /* defs.h */ #ifdef UNICODE |