]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/include/rocksdb/utilities/lua/rocks_lua_util.h
1 // Copyright (c) 2016, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
18 #include "rocksdb/utilities/lua/rocks_lua_custom_library.h"
20 namespace ROCKSDB_NAMESPACE
{
22 class LuaStateWrapper
{
24 explicit LuaStateWrapper(const std::string
& lua_script
) {
25 lua_state_
= luaL_newstate();
29 const std::string
& lua_script
,
30 const std::vector
<std::shared_ptr
<RocksLuaCustomLibrary
>>& libraries
) {
31 lua_state_
= luaL_newstate();
32 Init(lua_script
, libraries
);
34 lua_State
* GetLuaState() const { return lua_state_
; }
35 ~LuaStateWrapper() { lua_close(lua_state_
); }
39 const std::string
& lua_script
,
40 const std::vector
<std::shared_ptr
<RocksLuaCustomLibrary
>>& libraries
) {
42 luaL_openlibs(lua_state_
);
43 for (const auto& library
: libraries
) {
44 luaL_openlib(lua_state_
, library
->Name(), library
->Lib(), 0);
45 library
->CustomSetup(lua_state_
);
47 luaL_dostring(lua_state_
, lua_script
.c_str());
51 lua_State
* lua_state_
;
54 } // namespace ROCKSDB_NAMESPACE