5 #include "LuaService.hpp" 6 #include <rtt/plugin/ServicePlugin.hpp> 18 #define LuaService LuaTLSFService 20 #define LuaService LuaService 27 LuaService::LuaService(RTT::TaskContext* tc)
29 : RTT::Service(
"LuaTLSF", tc)
31 : RTT::Service(
"Lua", tc)
35 os::MutexLock lock(m);
39 if(tlsf_rtt_init_mp(tlsf_inf, TLSF_INITIAL_POOLSIZE)) {
40 Logger::log(Logger::Error) <<
"LuaService (TLSF)'" 41 << this->getOwner()->getName() <<
": failed to create tlsf pool (" 42 << std::hex << TLSF_INITIAL_POOLSIZE <<
"bytes)" << endlog();
46 L = lua_newstate(tlsf_alloc, tlsf_inf);
48 set_context_tlsf_info(tlsf_inf);
55 Logger::log(Logger::Error) <<
"LuaService ctr '" << this->getOwner()->getName() <<
"': " 56 <<
"cannot create state: not enough memory" << endlog();
61 lua_gc(L, LUA_GCSTOP, 0);
63 lua_gc(L, LUA_GCRESTART, 0);
66 lua_pushcfunction(L, luaopen_rtt);
69 set_context_tc(tc, L);
71 this->addOperation(
"exec_file", &LuaService::exec_file,
this)
72 .doc(
"load (and run) the given lua script")
73 .arg(
"filename",
"filename of the lua script");
75 this->addOperation(
"exec_str", &LuaService::exec_str,
this)
76 .doc(
"evaluate the given string in the lua environment")
77 .arg(
"lua-string",
"string of lua code to evaluate");
80 this->addOperation(
"tlsf_incmem", &LuaService::tlsf_incmem,
this, OwnThread)
81 .doc(
"increase the TLSF memory pool")
82 .arg(
"size",
"size in bytes to add to pool");
87 LuaService::~LuaService()
89 os::MutexLock lock(m);
92 tlsf_rtt_free_mp(tlsf_inf);
99 bool LuaService::tlsf_incmem(
unsigned int size)
101 return tlsf_rtt_incmem(tlsf_inf, size);
105 bool LuaService::exec_file(
const std::string &file)
107 os::MutexLock lock(m);
108 if (luaL_dofile(L, file.c_str())) {
109 Logger::log(Logger::Error) <<
"LuaService '" << this->getOwner()->getName()
110 <<
"': " << lua_tostring(L, -1) << endlog();
116 bool LuaService::exec_str(
const std::string &str)
118 os::MutexLock lock(m);
119 if (luaL_dostring(L, str.c_str())) {
120 Logger::log(Logger::Error) <<
"LuaService '" << this->getOwner()->getName()
121 <<
"': " << lua_tostring(L, -1) << endlog();
137 ORO_SERVICE_NAMED_PLUGIN(
LuaService ,
"LuaTLSF")
The Orocos Component Library.