| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- #include <cln/cln.h>
- extern "C"
- {
- #include "lua.h"
- #include "lualib.h"
- #include "lauxlib.h"
- }
- #include <luabind/luabind.hpp>
- void bind_cln(lua_State* L)
- {
- using namespace luabind;
- using namespace cln;
- module(L)
- [
- // real numbers
- class_<cl_R>("cl_R")
- .def(constructor<>())
- .def(constructor<const cl_I&>())
- .def(constructor<float>())
- .def(constructor<const char*>())
- .def(tostring(const_self))
- .def(-self)
- .def(const_self + const_self)
- .def(const_self - const_self)
- .def(const_self * const_self)
- .def(const_self / const_self)
- .def(const_self <= const_self)
- .def(const_self < const_self)
- .def(const_self == const_self)
- .def(other<int>() + const_self)
- .def(other<int>() - const_self)
- .def(other<int>() * const_self)
- .def(other<int>() / const_self)
- .def(other<int>() <= const_self)
- .def(other<int>() < const_self)
- .def(const_self + other<int>())
- .def(const_self - other<int>())
- .def(const_self * other<int>())
- .def(const_self / other<int>())
- .def(const_self <= other<int>())
- .def(const_self < other<int>())
- ,
-
- // rational numbers
- class_<cl_RA, cl_R>("cl_RA")
- .def(constructor<>())
- .def(constructor<const cl_I&>())
- .def(constructor<int>())
- .def(constructor<const char*>())
- .def(tostring(const_self))
- .def(-self)
- .def(const_self + const_self)
- .def(const_self - const_self)
- .def(const_self * const_self)
- .def(const_self / const_self)
- .def(const_self <= const_self)
- .def(const_self < const_self)
- .def(const_self == const_self)
- .def(other<int>() + const_self)
- .def(other<int>() - const_self)
- .def(other<int>() * const_self)
- .def(other<int>() / const_self)
- .def(other<int>() <= const_self)
- .def(other<int>() < const_self)
- .def(const_self + other<int>())
- .def(const_self - other<int>())
- .def(const_self * other<int>())
- .def(const_self / other<int>())
- .def(const_self <= other<int>())
- .def(const_self < other<int>())
- ,
- // integers
- class_<cl_I, cl_RA>("cl_I")
- .def(constructor<>())
- .def(constructor<const cl_I&>())
- .def(constructor<int>())
- .def(constructor<const char*>())
- .def(tostring(const_self))
- .def(-self)
- .def(const_self + const_self)
- .def(const_self - const_self)
- .def(const_self * const_self)
- .def(const_self <= const_self)
- .def(const_self < const_self)
- .def(const_self == const_self)
- .def(other<int>() + const_self)
- .def(other<int>() - const_self)
- .def(other<int>() * const_self)
- .def(other<int>() <= const_self)
- .def(other<int>() < const_self)
- .def(const_self + other<int>())
- .def(const_self - other<int>())
- .def(const_self * other<int>())
- .def(const_self <= other<int>())
- .def(const_self < other<int>())
- ,
-
- def("factorial", &cln::factorial),
- def("sqrt", (const cl_R(*)(const cl_R&))&cln::sqrt)
- ];
- }
- int main()
- {
- lua_State* L = lua_open();
- lua_baselibopen(L);
- lua_mathlibopen(L);
- luabind::open(L);
- bind_cln(L);
- lua_dofile(L, "cln_test.lua");
- lua_close(L);
- return 0;
- }
|