diff --git a/include/tarantool_lua.h b/include/tarantool_lua.h index af20890bde6bec465a9fdcb3cc86071c2df7bb83..0c4fc9456a50715ef176505f7014c13792c264bd 100644 --- a/include/tarantool_lua.h +++ b/include/tarantool_lua.h @@ -29,18 +29,26 @@ * SUCH DAMAGE. */ #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. * * @return L on success, 0 if out of memory */ -struct lua_State *mod_lua_init(struct lua_State *L); +struct lua_State * +mod_lua_init(struct lua_State *L); void tarantool_lua_register_type(struct lua_State *L, const char *type_name, @@ -55,33 +63,43 @@ tarantool_lua_register_type(struct lua_State *L, const char *type_name, * * @return L on success, 0 if out of memory */ -struct lua_State *tarantool_lua_init(); -void tarantool_lua_close(struct lua_State *L); +struct lua_State * +tarantool_lua_init(); -/* - * Single global lua_State shared by core and modules. - * Created with 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. */ -extern struct lua_State *tarantool_L; -/* Call Lua 'tostring' built-in to print userdata nicely. */ const char * tarantool_lua_tostring(struct lua_State *L, int index); -/* Convert Lua string, number or cdata (u64) to 64bit value */ +/** + * 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); +/** + * 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 Lua State */ -void tarantool_lua_load_init_script(struct lua_State *L); +void +tarantool_lua_load_init_script(struct lua_State *L); + void tarantool_lua(struct lua_State *L, struct tbuf *out, const char *str); + #endif /* INCLUDES_TARANTOOL_LUA_H */ diff --git a/src/tarantool_lua.m b/src/tarantool_lua.m index e4afd5b20c0a904b5f516129341da6f363096ab0..de5b2d5bfe839ad3bda7605e006f9ddafa3179fa 100644 --- a/src/tarantool_lua.m +++ b/src/tarantool_lua.m @@ -46,12 +46,15 @@ #include <ctype.h> #include TARANTOOL_CONFIG -/** tarantool start-up file */ +/** + * tarantool start-up file + */ #define TARANTOOL_LUA_INIT_SCRIPT "init.lua" struct lua_State *tarantool_L; -/* Remember the output of the administrative console in the +/** + * Remember the output of the administrative console in the * registry, to use with 'print'. */ static void @@ -65,26 +68,31 @@ tarantool_lua_set_out(struct lua_State *L, const struct tbuf *out) lua_settable(L, LUA_REGISTRYINDEX); } -/* dup out from parent to child L. Used in fiber_create */ - -void +/** + * dup out from parent to child L. Used in fiber_create + */ +static void tarantool_lua_dup_out(struct lua_State *L, struct lua_State *child_L) { lua_pushthread(L); lua_gettable(L, LUA_REGISTRYINDEX); struct tbuf *out = (struct tbuf *) lua_topointer(L, -1); - lua_pop(L, 1); /* pop 'out' */ + /* pop 'out' */ + lua_pop(L, 1); if (out) tarantool_lua_set_out(child_L, out); } -/** {{{ box Lua library: common functions +/* + * {{{ box Lua library: common functions */ const char *boxlib_name = "box"; -/** Pack our BER integer into luaL_Buffer */ +/** + * Pack our BER integer into luaL_Buffer + */ static void luaL_addvarint32(luaL_Buffer *b, u32 u32) { @@ -99,11 +107,13 @@ uint64_t tarantool_lua_tointeger64(struct lua_State *L, int idx) { uint64_t result = 0; + switch (lua_type(L, idx)) { case LUA_TNUMBER: result = lua_tointeger(L, idx); break; - case LUA_TSTRING: { + case LUA_TSTRING: + { const char *arg = luaL_checkstring(L, idx); char *arge; errno = 0; @@ -112,22 +122,26 @@ tarantool_lua_tointeger64(struct lua_State *L, int idx) luaL_error(L, "lua_tointeger64: bad argument"); break; } - case LUA_TCDATA: { + case LUA_TCDATA: + { if (lua_type(L, idx) != LUA_TCDATA) luaL_error(L, "lua_tointeger64: cdata expected"); GCcdata *cd = cdataV(L->base + (idx - 1)); if (cd->typeid != CTID_INT64 && cd->typeid != CTID_UINT64) - luaL_error(L, "lua_tointeger64: unsupported cdata type"); + luaL_error(L, + "lua_tointeger64: unsupported cdata type"); result = *(uint64_t*)cdataptr(cd); break; } default: luaL_error(L, "lua_tointeger64: unsupported type"); } + return result; } -/* Convert box.pack() format specifier to Tarantool +/** + * Convert box.pack() format specifier to Tarantool * binary protocol UPDATE opcode */ static char format_to_opcode(char format) @@ -175,7 +189,8 @@ lbox_pack(struct lua_State *L) { luaL_Buffer b; const char *format = luaL_checkstring(L, 1); - int i = 2; /* first arg comes second */ + /* first arg comes second */ + int i = 2; int nargs = lua_gettop(L); u32 u32buf; u64 u64buf; @@ -186,38 +201,37 @@ lbox_pack(struct lua_State *L) while (*format) { if (i > nargs) - luaL_error(L, "box.pack: argument count does not match the format"); + luaL_error(L, "box.pack: argument count does not match " + "the format"); switch (*format) { case 'B': case 'b': /* signed and unsigned 8-bit integers */ u32buf = lua_tointeger(L, i); if (u32buf > 0xff) - luaL_error(L, "box.pack: argument too big for 8-bit integer"); + luaL_error(L, "box.pack: argument too big for " + "8-bit integer"); luaL_addchar(&b, (char) u32buf); break; - /* signed and unsigned 32-bit integers */ case 'I': case 'i': - { + /* signed and unsigned 32-bit integers */ u32buf = lua_tointeger(L, i); luaL_addlstring(&b, (char *) &u32buf, sizeof(u32)); break; - } case 'L': case 'l': - { + /* signed and unsigned 64-bit integers */ u64buf = tarantool_lua_tointeger64(L, i); luaL_addlstring(&b, (char *) &u64buf, sizeof(u64)); break; - } - /* Perl 'pack' BER-encoded integer */ case 'w': + /* Perl 'pack' BER-encoded integer */ luaL_addvarint32(&b, lua_tointeger(L, i)); break; - /* A sequence of bytes */ case 'A': case 'a': + /* A sequence of bytes */ str = luaL_checklstring(L, i, &size); luaL_addlstring(&b, str, size); break; @@ -227,8 +241,7 @@ lbox_pack(struct lua_State *L) u32buf = (u32) lua_tointeger(L, i); str = (char *) &u32buf; size = sizeof(u32); - } else - if (lua_type(L, i) == LUA_TCDATA) { + } else if (lua_type(L, i) == LUA_TCDATA) { u64buf = tarantool_lua_tointeger64(L, i); str = (char *) &u64buf; size = sizeof(u64); @@ -238,22 +251,31 @@ lbox_pack(struct lua_State *L) luaL_addvarint32(&b, size); luaL_addlstring(&b, str, size); break; - case '=': /* update tuple set foo=bar */ - case '+': /* set field+=val */ - case '&': /* set field&=val */ - case '|': /* set field|=val */ - case '^': /* set field^=val */ - case ':': /* splice */ - case '#': /* delete field */ - case '!': /* insert field */ - u32buf= (u32) lua_tointeger(L, i); /* field no */ + case '=': + /* update tuple set foo = bar */ + case '+': + /* set field += val */ + case '&': + /* set field & =val */ + case '|': + /* set field |= val */ + case '^': + /* set field ^= val */ + case ':': + /* splice */ + case '#': + /* delete field */ + case '!': + /* insert field */ + /* field no */ + u32buf = (u32) lua_tointeger(L, i); luaL_addlstring(&b, (char *) &u32buf, sizeof(u32)); luaL_addchar(&b, format_to_opcode(*format)); break; default: luaL_error(L, "box.pack: unsupported pack " "format specifier '%c'", *format); - } /* end switch */ + } i++; format++; } @@ -288,7 +310,8 @@ static int lbox_unpack(struct lua_State *L) { const char *format = luaL_checkstring(L, 1); - int i = 2; /* first arg comes second */ + /* first arg comes second */ + int i = 2; int nargs = lua_gettop(L); size_t size; const char *str; @@ -296,12 +319,15 @@ lbox_unpack(struct lua_State *L) while (*format) { if (i > nargs) - luaL_error(L, "box.unpack: argument count does not match the format"); + luaL_error(L, "box.unpack: argument count does not " + "match the format"); switch (*format) { case 'i': str = lua_tolstring(L, i, &size); if (str == NULL || size != sizeof(u32)) - luaL_error(L, "box.unpack('%c'): got %d bytes (expected: 4)", *format, (int) size); + luaL_error(L, "box.unpack('%c'): got %d bytes " + "(expected: 4)", *format, + (int) size); u32buf = * (u32 *) str; lua_pushnumber(L, u32buf); break; @@ -309,7 +335,9 @@ lbox_unpack(struct lua_State *L) { str = lua_tolstring(L, i, &size); if (str == NULL || size != sizeof(u64)) - luaL_error(L, "box.unpack('%c'): got %d bytes (expected: 8)", *format, (int) size); + luaL_error(L, "box.unpack('%c'): got %d bytes " + "(expected: 8)", *format, + (int) size); GCcdata *cd = luaL_pushcdata(L, CTID_UINT64, 8); uint64_t *u64buf = (uint64_t*)cdataptr(cd); *u64buf = *(u64*)str; @@ -318,24 +346,27 @@ lbox_unpack(struct lua_State *L) default: luaL_error(L, "box.unpack: unsupported pack " "format specifier '%c'", *format); - } /* end switch */ + } i++; format++; } return i-2; } -/** A descriptor for box methods */ - +/** + * descriptor for box methods + */ static const struct luaL_reg boxlib[] = { {"pack", lbox_pack}, {"unpack", lbox_unpack}, {NULL, NULL} }; -/* }}} */ +/* + * }}} + */ -/** {{{ box.fiber Lua library: access to Tarantool/Box fibers +/* {{{ box.fiber Lua library: access to Tarantool/Box fibers * * Each fiber can be running, suspended or dead. * A fiber is created (box.fiber.create()) suspended. @@ -386,7 +417,9 @@ static const struct luaL_reg boxlib[] = { static const char *fiberlib_name = "box.fiber"; -/** Push a userdata for the given fiber onto Lua stack. */ +/** + * Push a userdata for the given fiber onto Lua stack. + */ static void lbox_pushfiber(struct lua_State *L, struct fiber *f) { @@ -397,39 +430,55 @@ lbox_pushfiber(struct lua_State *L, struct fiber *f) luaL_getmetatable(L, fiberlib_name); int top = lua_gettop(L); lua_getfield(L, -1, "memoize"); - if (lua_isnil(L, -1)) { /* first access - instantiate memoize */ - lua_pop(L, 1); /* pop the nil */ - lua_newtable(L); /* create memoize table */ - lua_newtable(L); /* and a metatable */ - lua_pushstring(L, "kv"); /* weak keys and values */ - lua_setfield(L, -2, "__mode"); /* pops 'kv' */ - lua_setmetatable(L, -2); /* pops the metatable */ - lua_setfield(L, -2, "memoize"); /* assigns and pops memoize */ - lua_getfield(L, -1, "memoize"); /* gets memoize back. */ + if (lua_isnil(L, -1)) { + /* first access - instantiate memoize */ + /* pop the nil */ + lua_pop(L, 1); + /* create memoize table */ + lua_newtable(L); + /* and a metatable */ + lua_newtable(L); + /* weak keys and values */ + lua_pushstring(L, "kv"); + /* pops 'kv' */ + lua_setfield(L, -2, "__mode"); + /* pops the metatable */ + lua_setmetatable(L, -2); + /* assigns and pops memoize */ + lua_setfield(L, -2, "memoize"); + /* gets memoize back. */ + lua_getfield(L, -1, "memoize"); assert(! lua_isnil(L, -1)); } /* Find out whether the fiber is already in the memoize table. */ lua_pushlightuserdata(L, f); lua_gettable(L, -2); - if (lua_isnil(L, -1)) { /* no userdata for fiber created so far */ - lua_pop(L, 1); /* pop the nil */ - lua_pushlightuserdata(L, f); /* push the key back */ + if (lua_isnil(L, -1)) { + /* no userdata for fiber created so far */ + /* pop the nil */ + lua_pop(L, 1); + /* push the key back */ + lua_pushlightuserdata(L, f); /* create a new userdata */ void **ptr = lua_newuserdata(L, sizeof(void *)); *ptr = f; luaL_getmetatable(L, fiberlib_name); lua_setmetatable(L, -2); - lua_settable(L, -3); /* memoize it */ + /* memoize it */ + lua_settable(L, -3); lua_pushlightuserdata(L, f); - lua_gettable(L, -2); /* get it back */ + /* get it back */ + lua_gettable(L, -2); } /* * Here we have a userdata on top of the stack and * possibly some garbage just under the top. Move the * result to the beginning of the stack and clear the rest. */ - lua_replace(L, top); /* moves the current top to the old top */ - lua_settop(L, top); /* clears everything after the old top */ + /* moves the current top to the old top */ + lua_replace(L, top); + /* clears everything after the old top */ + lua_settop(L, top); } static struct fiber * @@ -504,7 +553,6 @@ lbox_fiber_gc(struct lua_State *L) return 0; } - static void box_lua_fiber_run(void *arg __attribute__((unused))) { @@ -524,8 +572,10 @@ box_lua_fiber_run(void *arg __attribute__((unused))) */ @try { lua_call(L, lua_gettop(L) - 1, LUA_MULTRET); - lua_pushboolean(L, true); /* push completion status */ - lua_insert(L, 1); /* move 'true' to stack start */ + /* push completion status */ + lua_pushboolean(L, true); + /* move 'true' to stack start */ + lua_insert(L, 1); } @catch (ClientError *e) { /* * Note: FiberCancelException passes through this @@ -534,9 +584,12 @@ box_lua_fiber_run(void *arg __attribute__((unused))) * cancel a fiber which is not scheduled, and * cancel() is synchronous. */ - lua_settop(L, 0); /* pop any possible garbage */ - lua_pushboolean(L, false); /* completion status */ - lua_pushstring(L, e->errmsg); /* error message */ + /* pop any possible garbage */ + lua_settop(L, 0); + /* completion status */ + lua_pushboolean(L, false); + /* error message */ + lua_pushstring(L, e->errmsg); } @finally { /* * If the coroutine has detached itself, collect @@ -550,18 +603,20 @@ box_lua_fiber_run(void *arg __attribute__((unused))) static int lbox_fiber_create(struct lua_State *L) { - if (lua_gettop(L) != 1 || !lua_isfunction(L, 1)) - luaL_error(L, "fiber.create(function): bad arguments"); - if (fiber_checkstack()) { + if (lua_gettop(L) != 1 || !lua_isfunction(L, 1)) + luaL_error(L, "fiber.create(function): bad arguments"); + if (fiber_checkstack()) luaL_error(L, "fiber.create(function): recursion limit" " reached"); - } - struct fiber *f= fiber_create("lua", -1, box_lua_fiber_run, NULL); - lua_pushlightuserdata(L, f); /* associate coro with fiber */ + struct fiber *f = fiber_create("lua", -1, box_lua_fiber_run, NULL); + + /* associate coro with fiber */ + lua_pushlightuserdata(L, f); struct lua_State *child_L = lua_newthread(L); lua_settable(L, LUA_REGISTRYINDEX); - lua_xmove(L, child_L, 1); /* move the argument to the new coro */ + /* move the argument to the new coro */ + lua_xmove(L, child_L, 1); lbox_pushfiber(L, f); return 1; } @@ -584,14 +639,15 @@ lbox_fiber_resume(struct lua_State *L) /* Get the results */ nargs = lua_gettop(child_L); lua_xmove(child_L, L, nargs); - if (f->f == 0) { /* The fiber is dead. */ - /* Garbage collect the associated coro. */ + if (f->f == 0) { + /* The fiber is dead. Garbage collect the associated coro. */ box_lua_fiber_clear_coro(L, f); } return nargs; } -/** Yield the current fiber. +/** + * Yield the current fiber. * * Yield control to the calling fiber -- if the fiber * is attached, or to sched otherwise. @@ -607,7 +663,8 @@ lbox_fiber_yield(struct lua_State *L) * whatever arguments are taken. */ fiber_yield(); - fiber_testcancel(); /* throws an error if we were cancelled. */ + /* throws an error if we were cancelled. */ + fiber_testcancel(); /* * Got resumed. Return whatever the caller has passed * to us with box.fiber.resume(). @@ -668,11 +725,13 @@ lbox_fiber_detach(struct lua_State *L) fiber_wakeup(fiber); /* Yield to the parent. */ fiber_yield(); - fiber_testcancel(); /* check if we were cancelled. */ + /* check if we were cancelled. */ + fiber_testcancel(); return 0; } -/** Yield to the sched fiber and sleep. +/** + * Yield to the sched fiber and sleep. * @param[in] amount of time to sleep (double) * * Only the current fiber can be made to sleep. @@ -706,7 +765,8 @@ lbox_fiber_find(struct lua_State *L) return 1; } -/** Running and suspended fibers can be cancelled. +/** + * Running and suspended fibers can be cancelled. * Zombie fibers can't. */ static int @@ -754,28 +814,26 @@ static const struct luaL_reg fiberlib[] = { {NULL, NULL} }; -/* }}} */ - /* - * 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) { - if (index < 0) /* we need an absolute index */ + /* we need an absolute index */ + if (index < 0) index = lua_gettop(L) + index + 1; lua_getglobal(L, "tostring"); lua_pushvalue(L, index); - lua_call(L, 1, 1); /* pops both "tostring" and its argument */ + /* pops both "tostring" and its argument */ + lua_call(L, 1, 1); lua_replace(L, index); return lua_tostring(L, index); } -/* - * Convert Lua stack to YAML and append to - * the given tbuf. +/** + * Convert Lua stack to YAML and append to the given tbuf. */ static void tarantool_lua_printstack_yaml(struct lua_State *L, struct tbuf *out) @@ -787,11 +845,12 @@ tarantool_lua_printstack_yaml(struct lua_State *L, struct tbuf *out) int len = strlen(sz); tbuf_printf(out, " - %-.*s\r\n", len - 3, sz); } else - tbuf_printf(out, " - %s\r\n", tarantool_lua_tostring(L, i)); + tbuf_printf(out, " - %s\r\n", + tarantool_lua_tostring(L, i)); } } -/* +/** * A helper to serialize arguments of 'print' Lua built-in * to tbuf. */ @@ -831,14 +890,17 @@ lbox_print(struct lua_State *L) lua_pushthread(L); lua_gettable(L, LUA_REGISTRYINDEX); struct tbuf *out = (struct tbuf *) lua_topointer(L, -1); - lua_pop(L, 1); /* pop 'out' */ + /* pop 'out' */ + lua_pop(L, 1); - if (out) { /* Administrative console */ + if (out) { + /* Administrative console */ tarantool_lua_printstack(L, out); /* Courtesy: append YAML's \r\n if it's not already there */ if (out->size < 2 || tbuf_str(out)[out->size-1] != '\n') tbuf_printf(out, "\r\n"); - } else { /* Add a message to the server log */ + } else { + /* Add a message to the server log */ out = tbuf_alloc(fiber->gc_pool); tarantool_lua_printstack(L, out); say_info("%s", tbuf_str(out)); @@ -852,7 +914,6 @@ lbox_print(struct lua_State *L) * * See Lua documentation on 'pcall' for additional information. */ - static int lbox_pcall(struct lua_State *L) { @@ -862,22 +923,27 @@ lbox_pcall(struct lua_State *L) */ @try { lua_call(L, lua_gettop(L) - 1, LUA_MULTRET); - lua_pushboolean(L, true); /* push completion status */ - lua_insert(L, 1); /* move 'true' to stack start */ + /* push completion status */ + lua_pushboolean(L, true); + /* move 'true' to stack start */ + lua_insert(L, 1); } @catch (ClientError *e) { /* * Note: FiberCancelException passes through this * catch and thus leaves garbage on coroutine * stack. */ - lua_settop(L, 0); /* pop any possible garbage */ - lua_pushboolean(L, false); /* completion status */ - lua_pushstring(L, e->errmsg); /* error message */ + /* pop any possible garbage */ + lua_settop(L, 0); + /* completion status */ + lua_pushboolean(L, false); + /* error message */ + lua_pushstring(L, e->errmsg); } return lua_gettop(L); } -/* +/** * Convert lua number or string to lua cdata 64bit number. */ static int @@ -887,7 +953,9 @@ lbox_tonumber64(struct lua_State *L) return luaL_pushnumber64(L, result); } -/** A helper to register a single type metatable. */ +/** + * A helper to register a single type metatable. + */ void tarantool_lua_register_type(struct lua_State *L, const char *type_name, const struct luaL_Reg *methods) @@ -937,7 +1005,8 @@ tarantool_lua_init() lua_register(L, "pcall", lbox_pcall); lua_register(L, "tonumber64", lbox_tonumber64); L = mod_lua_init(L); - lua_settop(L, 0); /* clear possible left-overs of init */ + /* clear possible left-overs of init */ + lua_settop(L, 0); return L; } @@ -945,7 +1014,8 @@ void tarantool_lua_close(struct lua_State *L) { luaL_unref(L, LUA_REGISTRYINDEX, ffi_ref); - lua_close(L); /* collects garbage, invoking userdata gc */ + /* collects garbage, invoking userdata gc */ + lua_close(L); } /** @@ -961,7 +1031,8 @@ tarantool_lua_dostring(struct lua_State *L, const char *str) tbuf_printf(buf, "%s%s", "return ", str); int r = luaL_loadstring(L, tbuf_str(buf)); if (r) { - lua_pop(L, 1); /* pop the error message */ + /* pop the error message */ + lua_pop(L, 1); r = luaL_loadstring(L, str); if (r) return r; @@ -995,11 +1066,11 @@ tarantool_lua(struct lua_State *L, tbuf_printf(out, "error: '%s'\r\n", luaL_gsub(L, lua_tostring(L, -1), "'", "''")); - } - else { + } else { tarantool_lua_printstack_yaml(L, out); } - lua_settop(L, 0); /* clear the stack from return values. */ + /* clear the stack from return values. */ + lua_settop(L, 0); } /** @@ -1015,11 +1086,12 @@ is_string(const char *str) return true; char *endptr; double r = strtod(str, &endptr); - (void) r; /* -Wunused-result warning suppression */ + /* -Wunused-result warning suppression */ + (void) r; return *endptr != '\0'; } -/* +/** * Make a new configuration available in Lua. * We could perhaps make Lua bindings to access the C * structure in question, but for now it's easier and just @@ -1035,15 +1107,16 @@ tarantool_lua_load_cfg(struct lua_State *L, struct tarantool_cfg *cfg) luaL_buffinit(L, &b); tarantool_cfg_iterator_t *i = tarantool_cfg_iterator_init(); luaL_addstring(&b, -"box.cfg = {}\n" -"setmetatable(box.cfg, {})\n" -"box.space = {}\n" -"setmetatable(box.space, getmetatable(box.cfg))\n" -"getmetatable(box.space).__index = function(table, index)\n" -" table[index] = {}\n" -" setmetatable(table[index], getmetatable(table))\n" -" return rawget(table, index)\n" -"end\n"); + "box.cfg = {}\n" + "setmetatable(box.cfg, {})\n" + "box.space = {}\n" + "setmetatable(box.space, getmetatable(box.cfg))\n" + "getmetatable(box.space).__index = " + "function(table, index)\n" + " table[index] = {}\n" + " setmetatable(table[index], getmetatable(table))\n" + " return rawget(table, index)\n" + "end\n"); while ((key = tarantool_cfg_iterator_next(i, cfg, &value)) != NULL) { if (value == NULL) continue; @@ -1060,13 +1133,15 @@ tarantool_lua_load_cfg(struct lua_State *L, struct tarantool_cfg *cfg) free(value); } luaL_addstring(&b, -"getmetatable(box.cfg).__newindex = function(table, index)\n" -" error('Attempt to modify a read-only table')\n" -"end\n" -"getmetatable(box.cfg).__index = nil\n" -"if type(box.on_reload_configuration) == 'function' then\n" -" box.on_reload_configuration()\n" -"end\n"); + "getmetatable(box.cfg).__newindex = " + "function(table, index)\n" + " error('Attempt to modify a read-only table')\n" + "end\n" + "getmetatable(box.cfg).__index = nil\n" + "if type(box.on_reload_configuration) == 'function' " + "then\n" + " box.on_reload_configuration()\n" + "end\n"); luaL_pushresult(&b); if (luaL_loadstring(L, lua_tostring(L, -1)) != 0 || lua_pcall(L, 0, 0, 0) != 0) { @@ -1076,7 +1151,7 @@ tarantool_lua_load_cfg(struct lua_State *L, struct tarantool_cfg *cfg) } /** - * Load start-up file routine + * Load start-up file routine. */ static void load_init_script(void *L_ptr) @@ -1100,7 +1175,8 @@ load_init_script(void *L_ptr) */ } -void tarantool_lua_load_init_script(struct lua_State *L) +void +tarantool_lua_load_init_script(struct lua_State *L) { /* * init script can call box.fiber.yield (including implicitly via