1 #include <cln/cln.h> 2 3 extern "C" 4 { 5 #include "lua.h" 6 #include "lualib.h" 7 #include "lauxlib.h" 8 } 9 10 #include <luabind/luabind.hpp> 11 bind_cln(lua_State * L)12void bind_cln(lua_State* L) 13 { 14 using namespace luabind; 15 using namespace cln; 16 17 module(L) 18 [ 19 // real numbers 20 class_<cl_R>("cl_R") 21 .def(constructor<>()) 22 .def(constructor<const cl_I&>()) 23 .def(constructor<float>()) 24 .def(constructor<const char*>()) 25 .def(tostring(const_self)) 26 .def(-self) 27 .def(const_self + const_self) 28 .def(const_self - const_self) 29 .def(const_self * const_self) 30 .def(const_self / const_self) 31 .def(const_self <= const_self) 32 .def(const_self < const_self) 33 .def(const_self == const_self) 34 .def(other<int>() + const_self) 35 .def(other<int>() - const_self) 36 .def(other<int>() * const_self) 37 .def(other<int>() / const_self) 38 .def(other<int>() <= const_self) 39 .def(other<int>() < const_self) 40 .def(const_self + other<int>()) 41 .def(const_self - other<int>()) 42 .def(const_self * other<int>()) 43 .def(const_self / other<int>()) 44 .def(const_self <= other<int>()) 45 .def(const_self < other<int>()) 46 , 47 48 // rational numbers 49 class_<cl_RA, cl_R>("cl_RA") 50 .def(constructor<>()) 51 .def(constructor<const cl_I&>()) 52 .def(constructor<int>()) 53 .def(constructor<const char*>()) 54 .def(tostring(const_self)) 55 .def(-self) 56 .def(const_self + const_self) 57 .def(const_self - const_self) 58 .def(const_self * const_self) 59 .def(const_self / const_self) 60 .def(const_self <= const_self) 61 .def(const_self < const_self) 62 .def(const_self == const_self) 63 .def(other<int>() + const_self) 64 .def(other<int>() - const_self) 65 .def(other<int>() * const_self) 66 .def(other<int>() / const_self) 67 .def(other<int>() <= const_self) 68 .def(other<int>() < const_self) 69 .def(const_self + other<int>()) 70 .def(const_self - other<int>()) 71 .def(const_self * other<int>()) 72 .def(const_self / other<int>()) 73 .def(const_self <= other<int>()) 74 .def(const_self < other<int>()) 75 , 76 77 // integers 78 class_<cl_I, cl_RA>("cl_I") 79 .def(constructor<>()) 80 .def(constructor<const cl_I&>()) 81 .def(constructor<int>()) 82 .def(constructor<const char*>()) 83 .def(tostring(const_self)) 84 .def(-self) 85 .def(const_self + const_self) 86 .def(const_self - const_self) 87 .def(const_self * const_self) 88 .def(const_self <= const_self) 89 .def(const_self < const_self) 90 .def(const_self == const_self) 91 .def(other<int>() + const_self) 92 .def(other<int>() - const_self) 93 .def(other<int>() * const_self) 94 .def(other<int>() <= const_self) 95 .def(other<int>() < const_self) 96 .def(const_self + other<int>()) 97 .def(const_self - other<int>()) 98 .def(const_self * other<int>()) 99 .def(const_self <= other<int>()) 100 .def(const_self < other<int>()) 101 , 102 103 def("factorial", &cln::factorial), 104 def("sqrt", (const cl_R(*)(const cl_R&))&cln::sqrt) 105 ]; 106 } 107 main()108int main() 109 { 110 lua_State* L = luaL_newstate(); 111 lua_baselibopen(L); 112 lua_mathlibopen(L); 113 luabind::open(L); 114 115 bind_cln(L); 116 117 lua_dofile(L, "cln_test.lua"); 118 119 lua_close(L); 120 return 0; 121 } 122