Covalent Bond  0.0.1-alpha
'covalent bond' is a data middle office. As a 2022-2023 Fall SWE final project.
luaEngine.cpp
Go to the documentation of this file.
1 
11 #include "luaEngine.hpp"
12 
13 void bindAllFuncByDefault(sol::state* handle) {
14  (*handle).script_file("/home/wang/covalentBond/scripts/libCB.lua");
15 
16  auto covalentBound = (*handle)["Cb"].get_or_create<sol::table>();
17  auto covalentBoundF = covalentBound["F"].get_or_create<sol::table>();
18  // Bind Make Shape Function
19  covalentBoundF.set_function("makeShapeFull", makeShapeFull);
20  covalentBoundF.set_function("makeShapeCol", makeShapeCol);
21  covalentBoundF.set_function("makeShapeRow", makeShapeRow);
22 
23  // Bind MySQLCell to lua.
24  covalentBound.new_usertype<cbMySQLCell>(
25 
26  "KVCell",
27 
28  sol::meta_function::construct,
29  sol::factories(
30  [](const float& value) { return MAKE_SHARED(cbMySQLCell)(value); },
31  [](const double& value) { return MAKE_SHARED(cbMySQLCell)(value); },
32  [](const std::string& value) { return MAKE_SHARED(cbMySQLCell)(value); },
33  [](const int& value) { return MAKE_SHARED(cbMySQLCell)(value); },
34  [](const unsigned long long& value) { return MAKE_SHARED(cbMySQLCell)(value); }),
35 
36  sol::call_constructor,
37  sol::factories(
38  [](const float& value) { return MAKE_SHARED(cbMySQLCell)(value); },
39  [](const double& value) { return MAKE_SHARED(cbMySQLCell)(value); },
40  [](const std::string& value) { return MAKE_SHARED(cbMySQLCell)(value); },
41  [](const int& value) { return MAKE_SHARED(cbMySQLCell)(value); },
42  [](const unsigned long long& value) { return MAKE_SHARED(cbMySQLCell)(value); }),
43 
44  "asInt", &cbMySQLCell::asInt,
45 
46  "asFloat", &cbMySQLCell::asFloat,
47 
48  "asDouble", &cbMySQLCell::asDouble,
49 
50  "asULL", &cbMySQLCell::asULL,
51 
52  "asString", &cbMySQLCell::asString,
53 
54  "asTime", &cbMySQLCell::asTime,
55 
56  "asDataTime", &cbMySQLCell::asDatetime,
57 
58  "setInt", &cbMySQLCell::setInt,
59 
60  "setFloat", &cbMySQLCell::setFloat,
61 
62  "setULL", &cbMySQLCell::setULL,
63 
64  "setString", &cbMySQLCell::setString,
65 
66  "setTime", &cbMySQLCell::setTime,
67 
68  "setDataTime", &cbMySQLCell::setDatetime,
69 
70  "isInt", &cbMySQLCell::isInt,
71 
72  "isFloat", &cbMySQLCell::isFloat,
73 
74  "isULL", &cbMySQLCell::isULL,
75 
76  "isString", &cbMySQLCell::isString,
77 
78  "isTime", &cbMySQLCell::isTime,
79 
80  "isDataTime", &cbMySQLCell::isDatetime,
81 
82  "isDouble", &cbMySQLCell::isDouble
83 
84  );
85 }
86 
88  m_luaHandle->collect_garbage();
89  m_luaHandle->collect_gc();
90  delete m_luaHandle;
91 }
92 
93 luaJitThread::luaJitThread() : m_luaHandle(new sol::state()) {
94  m_luaHandle->open_libraries(sol::lib::base);
96 }
97 
98 void luaJitThread::execMain(const std::string& script) { m_luaHandle->script(script); }
99 
100 sol::state& luaJitThread::operator()() { return *m_luaHandle; }
luaJitThread::operator()
sol::state & operator()()
Definition: luaEngine.cpp:100
luaJitThread::luaJitThread
luaJitThread()
Definition: luaEngine.cpp:93
cbMySQLCell::isTime
bool isTime() const
Definition: cbTable.cpp:388
cbMySQLCell::isDouble
bool isDouble() const
Definition: cbTable.cpp:367
cbMySQLCell::setTime
void setTime(const std::string &value)
Definition: cbTable.cpp:457
cbMySQLCell::asTime
std::string asTime() const
Definition: cbTable.cpp:429
luaJitThread::m_luaHandle
sol::state * m_luaHandle
Definition: luaEngine.hpp:56
cbMySQLCell::asDouble
double asDouble() const
Definition: cbTable.cpp:417
makeShapeCol
cbShape< 2 > makeShapeCol(int32_t a)
Definition: cbTable.hpp:184
cbMySQLCell
Definition: cbTable.hpp:468
cbMySQLCell::isFloat
bool isFloat() const
Definition: cbTable.cpp:360
cbMySQLCell::isDatetime
bool isDatetime() const
Definition: cbTable.cpp:395
cbMySQLCell::isInt
bool isInt() const
Definition: cbTable.cpp:343
cbMySQLCell::setDatetime
void setDatetime(const std::string &value)
Definition: cbTable.cpp:461
cbMySQLCell::asULL
unsigned long long asULL() const
Definition: cbTable.cpp:422
cbMySQLCell::setFloat
void setFloat(float value)
Definition: cbTable.cpp:441
cbMySQLCell::isULL
bool isULL() const
Definition: cbTable.cpp:374
luaJitThread::execMain
void execMain(const std::string &script)
Definition: luaEngine.cpp:98
cbMySQLCell::asInt
int asInt() const
Definition: cbTable.cpp:402
cbMySQLCell::isString
bool isString() const
Definition: cbTable.cpp:350
cbMySQLCell::setInt
void setInt(int value)
Definition: cbTable.cpp:433
bindAllFuncByDefault
void bindAllFuncByDefault(sol::state *handle)
_WIN32
Definition: luaEngine.cpp:13
cbMySQLCell::setString
void setString(const std::string &value)
Definition: cbTable.cpp:437
cbMySQLCell::asDatetime
std::string asDatetime() const
Definition: cbTable.cpp:431
makeShapeFull
cbShape< 2 > makeShapeFull(int32_t a, int32_t b)
Definition: cbTable.hpp:198
luaJitThread::~luaJitThread
~luaJitThread()
Definition: luaEngine.cpp:87
cbMySQLCell::asFloat
float asFloat() const
Definition: cbTable.cpp:412
cbMySQLCell::asString
std::string asString() const
Definition: cbTable.cpp:407
MAKE_SHARED
#define MAKE_SHARED(x)
Definition: pch.hpp:182
makeShapeRow
cbShape< 2 > makeShapeRow(int32_t a)
Definition: cbTable.hpp:171
luaEngine.hpp
A lua engine for execute all c++ embedding in struct. A warper of lua JIT engine.
cbMySQLCell::setULL
void setULL(unsigned long long value)
Definition: cbTable.cpp:449