1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#ifndef INCLUDES_TARANTOOL_LUA_H
#define INCLUDES_TARANTOOL_LUA_H
/*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* 1. Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <stddef.h>
#include <inttypes.h>
struct lua_State;
struct luaL_Reg;
struct tarantool_cfg;
struct tbuf;
/*
* Single global lua_State shared by core and modules.
* Created with tarantool_lua_init().
*/
extern struct lua_State *tarantool_L;
/**
* This is a callback used by tarantool_lua_init() to open
* module-specific libraries into given Lua state.
*
* No return value, panics if error.
*/
void
mod_lua_init(struct lua_State *L);
void
tarantool_lua_register_type(struct lua_State *L, const char *type_name,
const struct luaL_Reg *methods);
/**
* Create an instance of Lua interpreter and load it with
* Tarantool modules. Creates a Lua state, imports global
* Tarantool modules, then calls mod_lua_init(), which performs
* module-specific imports. The created state can be freed as any
* other, with lua_close().
*
* @return L on success, 0 if out of memory
*/
struct lua_State *
tarantool_lua_init();
void
tarantool_lua_close(struct lua_State *L);
/**
* This function exists because lua_tostring does not use
* __tostring metamethod, and this metamethod has to be used
* if we want to print Lua userdata correctly.
*/
const char *
tarantool_lua_tostring(struct lua_State *L, int index);
/**
* Convert Lua string, number or cdata (u64) to 64bit value
*/
uint64_t
tarantool_lua_tointeger64(struct lua_State *L, int idx);
/**
* Make a new configuration available in Lua
*/
void
tarantool_lua_load_cfg(struct lua_State *L,
struct tarantool_cfg *cfg);
/**
* Load and execute start-up file
*
* @param L is a Lua State.
*/
void
tarantool_lua_load_init_script(struct lua_State *L);
void
tarantool_lua(struct lua_State *L,
struct tbuf *out, const char *str);
/**
* push uint64_t to Lua stack
*
* @param L is a Lua State
* @param val is a value to push
*
*/
int luaL_pushnumber64(struct lua_State *L, uint64_t val);
/**
* show plugin statistics (for admin port)
*/
struct tbuf;
void show_plugins_stat(struct tbuf *out);
/**
* @brief A palloc-like wrapper to allocate memory using lua_newuserdata
* @param ctx lua_State
* @param size a number of bytes to allocate
* @return a pointer to the allocated memory
*/
void *
lua_region_alloc(void *ctx, size_t size);
#endif /* INCLUDES_TARANTOOL_LUA_H */
|