]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/include/rocksdb/utilities/lua/rocks_lua_custom_library.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / rocksdb / include / rocksdb / utilities / lua / rocks_lua_custom_library.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).
5
6 #pragma once
7 #ifdef LUA
8
9 // lua headers
10 extern "C" {
11 #include <lauxlib.h>
12 #include <lua.h>
13 #include <lualib.h>
14 }
15
16 namespace ROCKSDB_NAMESPACE {
17 namespace lua {
18 // A class that used to define custom C Library that is callable
19 // from Lua script
20 class RocksLuaCustomLibrary {
21 public:
22 virtual ~RocksLuaCustomLibrary() {}
23 // The name of the C library. This name will also be used as the table
24 // (namespace) in Lua that contains the C library.
25 virtual const char* Name() const = 0;
26
27 // Returns a "static const struct luaL_Reg[]", which includes a list of
28 // C functions. Note that the last entry of this static array must be
29 // {nullptr, nullptr} as required by Lua.
30 //
31 // More details about how to implement Lua C libraries can be found
32 // in the official Lua document http://www.lua.org/pil/26.2.html
33 virtual const struct luaL_Reg* Lib() const = 0;
34
35 // A function that will be called right after the library has been created
36 // and pushed on the top of the lua_State. This custom setup function
37 // allows developers to put additional table or constant values inside
38 // the same table / namespace.
39 virtual void CustomSetup(lua_State* /*L*/) const {}
40 };
41 } // namespace lua
42 } // namespace ROCKSDB_NAMESPACE
43 #endif // LUA