Add access to space configuration to Lua.
Make configuration in Lua read-only.
---
 core/tarantool_lua.m |   26 ++++++++++++++++++++++----
 test/box/lua.result  |  Bin 8296 -> 8889 bytes
 test/box/lua.test    |    5 +++++
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/core/tarantool_lua.m b/core/tarantool_lua.m
index 1383bb0..84aefc2 100644
--- a/core/tarantool_lua.m
+++ b/core/tarantool_lua.m
@@ -370,21 +370,39 @@ void 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");
+       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");
        while ((key = tarantool_cfg_iterator_next(i, cfg, &value)) != NULL) {
                if (value == NULL)
                        continue;
+               char *quote = is_string(value) ? "'" : "";
                if (strchr(key, '.') == NULL) {
-                       char *quote = is_string(value) ? "'" : "";
                        lua_pushfstring(L, "box.cfg.%s = %s%s%s\n",
                                        key, quote, value, quote);
                        luaL_addstring(&b, lua_tostring(L, -1));
-                       free(value);
+                       lua_pop(L, 1);
+               } else if (strncmp(key, "namespace[", 10) == 0) {
+                       lua_pushfstring(L, "box.space%s = %s%s%s\n",
+                                       key+9, quote, value, quote);
+                       luaL_addstring(&b, lua_tostring(L, -1));
                        lua_pop(L, 1);
                }
+               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");
        luaL_pushresult(&b);
-       puts(lua_tostring(L, -1));
        if (luaL_loadstring(L, lua_tostring(L, -1)) == 0)
                lua_pcall(L, 0, 0, 0);
        lua_pop(L, 1);
diff --git a/test/box/lua.result b/test/box/lua.result
index 
c6dcdecb5e335f0fd68369fa6ef4ed532b7ed7bc..e5c41e6f8be45a4804ac07c91762aaabc538e16d
 100644
GIT binary patch
delta 446
zcmaFiu+w$I5!T{@#N^bCy98t=`%6lygL%;gv6>1g`3jk73MG{VsTyUP3U#&$>LrOu
zIjQOjB^jxClk+8I9TigZQn++=b$PiIbb)M;Y>JhFA()$-Sd@~Pmza}TQfZ~23lU2#
zF3HSIEJ;m?FUl`3wo)+Id{|~FGpW|5P;4zPm!6&;FIP@!qC!%Bg<f)6x?Wy>acOc!
zenClQex8D@g5l%|%u3-<Ng%(v7N|oh*2>htO2M(DBsI67M4=>KAvZrIGp$k~QK2X`
dF-12&FQ-xg5=Lk?Kmyg+z#tZ8wj;%60{}WEiVgq(

delta 15
Xcmdn#`odwtk&TzxWH#5y&SM4uKl}#}

diff --git a/test/box/lua.test b/test/box/lua.test
index f76a088..e4adf5d 100644
--- a/test/box/lua.test
+++ b/test/box/lua.test
@@ -101,5 +101,10 @@ exec admin "lua box.delete(0, 'test')"
 exec admin "lua fifo_top('test')"
 exec admin "lua box.delete(0, 'test')"
 exec admin "lua for k,v in pairs(box.cfg) do print(' - ', k, ': ', v) end"
+exec admin "lua for k,v in pairs(box.space[0]) do if type(v) ~= 'table' then 
print(' - ', k, ': ', v) end end"
 exec admin "reload configuration"
 exec admin "lua for k,v in pairs(box.cfg) do print(' - ', k, ': ', v) end"
+exec admin "lua for k,v in pairs(box.space[0]) do if type(v) ~= 'table' then 
print(' - ', k, ': ', v) end end"
+# must be read-only
+exec admin "lua box.cfg.nosuchoption = 1"
+exec admin "lua box.space[300] = 1"
-- 
1.7.0.4


_______________________________________________
Mailing list: https://launchpad.net/~tarantool-developers
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~tarantool-developers
More help   : https://help.launchpad.net/ListHelp

Reply via email to