@@ -36,12 +36,14 @@ static inline bool set_kv(lua_State *L, int keys_len, int value_idx) {
3636 lua_pushvalue (L , -2 ); // copy so we can continue with it after rawset
3737 lua_rawset (L , parent_idx ); // t[key] = new table
3838 } else if (vtype != LUA_TTABLE ) {
39+ // TODO: print keys
3940 return set_tmlerr (new_tmlerr (L , DECODE_DEFINED_IDX ), false, 18 , "key is not a table" );
4041 }
4142 lua_remove (L , parent_idx );
4243 // NOTE: We need to check if it was defined inline, because if it was defined by key in the same heading we can redefine but inline we can't
4344 lua_pushvalue (L , -1 );
4445 lua_rawget (L , DECODE_DEFINED_IDX );
46+ // TODO: print keys
4547 if (lua_tointeger (L , -1 ) == -2 ) return set_tmlerr (new_tmlerr (L , DECODE_DEFINED_IDX ), false, 36 , "Keys may not redefine inline tables!" );
4648 lua_pop (L , 1 );
4749 lua_pushvalue (L , -1 );
@@ -52,6 +54,7 @@ static inline bool set_kv(lua_State *L, int keys_len, int value_idx) {
5254 lua_pushvalue (L , -2 );
5355 lua_rawget (L , -2 );
5456 if (!lua_isnil (L , -1 )) {
57+ // TODO: print keys
5558 return set_tmlerr (new_tmlerr (L , DECODE_DEFINED_IDX ), false, 20 , "key already defined!" );
5659 }
5760 lua_pop (L , 1 );
@@ -81,6 +84,7 @@ static inline bool heading_nav(lua_State *L, int keys_len, bool array_type) {
8184 lua_pushvalue (L , -2 );
8285 lua_rawset (L , parent_idx ); // t[key] = new table
8386 } else if (vtype != LUA_TTABLE ) {
87+ // TODO: print keys
8488 return set_tmlerr (new_tmlerr (L , DECODE_DEFINED_IDX ), false, 33 , "cannot navigate through non-table" );
8589 }
8690 lua_remove (L , parent_idx ); // remove parent table, keep child on top
@@ -102,6 +106,7 @@ static inline bool heading_nav(lua_State *L, int keys_len, bool array_type) {
102106 lua_rawseti (L , parent_idx , len );
103107 lua_remove (L , parent_idx ); // remove parent table, keep child on top
104108 } else if (len != 0 ) {
109+ // TODO: print keys
105110 return set_tmlerr (new_tmlerr (L , DECODE_DEFINED_IDX ), false, 22 , "table already defined!" );
106111 } else {
107112 lua_pushvalue (L , -1 );
@@ -112,6 +117,7 @@ static inline bool heading_nav(lua_State *L, int keys_len, bool array_type) {
112117 lua_rawgeti (L , -1 , len );
113118 lua_remove (L , -2 );
114119 if (!lua_istable (L , -1 ))
120+ // TODO: print keys
115121 return set_tmlerr (new_tmlerr (L , DECODE_DEFINED_IDX ), false, 33 , "cannot navigate through non-table" );
116122 }
117123 }
@@ -163,11 +169,13 @@ int tomlua_decode(lua_State *L) {
163169 int keys_len = parse_keys (L , & src , & scratch , int_keys , DECODE_DEFINED_IDX );
164170 if (!keys_len ) goto fail ;
165171 if (!iter_starts_with (& src , "]]" , 2 )) {
172+ // TODO: print keys
166173 set_tmlerr (new_tmlerr (L , DECODE_DEFINED_IDX ), false, 30 , "table heading must end with ]]" );
167174 goto fail ;
168175 }
169176 iter_skip_n (& src , 2 ); // consume ]]
170177 if (!consume_whitespace_to_line (& src )) {
178+ // TODO: print keys
171179 set_tmlerr (new_tmlerr (L , DECODE_DEFINED_IDX ), false, 56 , "array [[headers]] must have a new line before new values" );
172180 goto fail ;
173181 }
@@ -178,11 +186,13 @@ int tomlua_decode(lua_State *L) {
178186 int keys_len = parse_keys (L , & src , & scratch , int_keys , DECODE_DEFINED_IDX );
179187 if (!keys_len ) goto fail ;
180188 if (iter_peek (& src ).v != ']' ) {
189+ // TODO: print keys
181190 set_tmlerr (new_tmlerr (L , DECODE_DEFINED_IDX ), false, 29 , "table heading must end with ]" );
182191 goto fail ;
183192 }
184193 iter_skip (& src ); // consume ]
185194 if (!consume_whitespace_to_line (& src )) {
195+ // TODO: print keys
186196 set_tmlerr (new_tmlerr (L , DECODE_DEFINED_IDX ), false, 54 , "table [headers] must have a new line before new values" );
187197 goto fail ;
188198 }
@@ -193,11 +203,13 @@ int tomlua_decode(lua_State *L) {
193203 int keys_len = parse_keys (L , & src , & scratch , int_keys , DECODE_DEFINED_IDX );
194204 if (!keys_len ) goto fail ;
195205 if (iter_peek (& src ).v != '=' ) {
206+ // TODO: print keys
196207 set_tmlerr (new_tmlerr (L , DECODE_DEFINED_IDX ), false, 35 , "keys for assignment must end with =" );
197208 goto fail ;
198209 }
199210 iter_skip (& src ); // consume =
200211 if (consume_whitespace_to_line (& src )) {
212+ // TODO: print keys
201213 set_tmlerr (new_tmlerr (L , DECODE_DEFINED_IDX ), false, 76 , "the value in key = value expressions must begin on the same line as the key!" );
202214 goto fail ;
203215 }
@@ -221,8 +233,9 @@ int tomlua_decode(lua_State *L) {
221233
222234fail :
223235 lua_settop (L , DECODE_DEFINED_IDX );
224- tmlerr_push_ctx_from_iter (get_err_val (L , DECODE_DEFINED_IDX ), 7 , & src );
225236 free_str_buf (& scratch );
237+ // TODO: figure out why this does not add context when pos == len
238+ tmlerr_push_ctx_from_iter (get_err_val (L , DECODE_DEFINED_IDX ), 7 , & src );
226239 lua_pushnil (L );
227240 push_tmlerr_string (L , get_err_val (L , DECODE_DEFINED_IDX ));
228241 return 2 ;
0 commit comments