From 9a4d5574a89c4a7842211238d8b9b30b905cc056 Mon Sep 17 00:00:00 2001 From: ame Date: Mon, 18 Dec 2023 13:55:13 -0600 Subject: config and io functions --- src/table.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/table.c') diff --git a/src/table.c b/src/table.c index 4e99cf1..6c3686a 100644 --- a/src/table.c +++ b/src/table.c @@ -1,10 +1,20 @@ #include "table.h" #include #include - +#include + +uint64_t i_len(lua_State* L, int pos){ + uint64_t i = 0; + lua_pushnil(L); + for(;lua_next(L,pos) != 0;){ + i += 1; + lua_pop(L,1); + } + return i; +} int l_len(lua_State* L) { - luaL_checktype(L, 1, LUA_TTABLE); - lua_pushnumber(L,lua_objlen(L,1)); + luaL_checktype(L, 1, LUA_TTABLE); + lua_pushnumber(L,i_len(L,1)); return 1; } @@ -178,7 +188,7 @@ int l_split(lua_State* L){ size_t split_len = 0; char* input = (char*)luaL_checklstring(L, 1, &input_len); char* split = (char*)luaL_checklstring(L, 2, &split_len); - size_t table_len = 0; + size_t table_len = 1; lua_newtable(L); size_t current_len = 0; -- cgit v1.2.3