]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_lua_utils.cc
3 #include "common/ceph_context.h"
4 #include "common/dout.h"
5 #include "rgw_lua_utils.h"
6 #include "rgw_lua_version.h"
8 #define dout_subsys ceph_subsys_rgw
12 // TODO - add the folowing generic functions
13 // lua_push(lua_State* L, const std::string& str)
14 // template<typename T> lua_push(lua_State* L, const std::optional<T>& val)
15 // lua_push(lua_State* L, const ceph::real_time& tp)
17 constexpr const char* RGWDebugLogAction
{"RGWDebugLog"};
19 int RGWDebugLog(lua_State
* L
)
21 auto cct
= reinterpret_cast<CephContext
*>(lua_touserdata(L
, lua_upvalueindex(1)));
23 auto message
= luaL_checkstring(L
, 1);
24 ldout(cct
, 20) << "Lua INFO: " << message
<< dendl
;
28 void create_debug_action(lua_State
* L
, CephContext
* cct
) {
29 lua_pushlightuserdata(L
, cct
);
30 lua_pushcclosure(L
, RGWDebugLog
, ONE_UPVAL
);
31 lua_setglobal(L
, RGWDebugLogAction
);
34 void stack_dump(lua_State
* L
) {
35 int top
= lua_gettop(L
);
36 std::cout
<< std::endl
<< " ---------------- Stack Dump ----------------" << std::endl
;
37 std::cout
<< "Stack Size: " << top
<< std::endl
;
38 for (int i
= 1, j
= -top
; i
<= top
; i
++, j
++) {
39 std::cout
<< "[" << i
<< "," << j
<< "]: " << luaL_tolstring(L
, i
, NULL
) << std::endl
;
42 std::cout
<< "--------------- Stack Dump Finished ---------------" << std::endl
;
45 void set_package_path(lua_State
* L
, const std::string
& install_dir
) {
46 if (install_dir
.empty()) {
49 lua_getglobal(L
, "package");
50 if (!lua_istable(L
, -1)) {
53 const auto path
= install_dir
+"/share/lua/"+CEPH_LUA_VERSION
+"/?.lua";
55 lua_setfield(L
, -2, "path");
57 const auto cpath
= install_dir
+"/lib/lua/"+CEPH_LUA_VERSION
+"/?.so";
59 lua_setfield(L
, -2, "cpath");
62 void open_standard_libs(lua_State
* L
) {
64 unsetglobal(L
, "load");
65 unsetglobal(L
, "loadfile");
66 unsetglobal(L
, "loadstring");
67 unsetglobal(L
, "dofile");
68 unsetglobal(L
, "debug");
70 lua_getglobal(L
, "os");
71 lua_pushstring(L
, "exit");