summaryrefslogtreecommitdiffstats
path: root/lua-squarkdb.c
diff options
context:
space:
mode:
Diffstat (limited to 'lua-squarkdb.c')
-rw-r--r--lua-squarkdb.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/lua-squarkdb.c b/lua-squarkdb.c
index 80a0d32..dbac6d0 100644
--- a/lua-squarkdb.c
+++ b/lua-squarkdb.c
@@ -266,6 +266,40 @@ static int Lsqdb_map_strings(lua_State *L)
return 0;
}
+static int Lsqdb_write_section(lua_State *L)
+{
+ struct sqdb *db;
+ uint32_t *ptr;
+ const char *section;
+ int i, tbllen, si = -1;
+
+ db = Lsqdb_checkarg(L, 1);
+ section = luaL_checkstring(L, 2);
+ luaL_checktype(L, 3, LUA_TTABLE);
+ tbllen = lua_objlen(L, 3);
+
+ for (i = 0; sqdb_section_names[i] && i < SQDB_SECTION_MAX; i++) {
+ if (strcmp(sqdb_section_names[i], section) == 0) {
+ si = 0;
+ break;
+ }
+ }
+ if (si < 0)
+ luaL_error(L, "Section name '%s' is invalid", section);
+
+ ptr = sqdb_section_create(db, i, sizeof(uint32_t) * tbllen);
+ if (ptr == NULL)
+ luaL_error(L, "Failed to create section '%s'", section);
+
+ for (i = 0; i < tbllen; i++) {
+ lua_rawgeti(L, 3, i + 1);
+ ptr[i] = lua_tointeger(L, -1);
+ lua_pop(L, 1);
+ }
+
+ return 0;
+}
+
static const luaL_reg sqdb_meta_methods[] = {
{ "__gc", Lsqdb_destroy },
{ NULL, NULL }
@@ -278,6 +312,7 @@ static const luaL_reg squarkdb_methods[] = {
{ "create_index", Lsqdb_create_index },
{ "assign_index", Lsqdb_assign_index },
{ "map_strings", Lsqdb_map_strings },
+ { "write_section", Lsqdb_write_section },
{ NULL, NULL }
};