@@ -36,15 +36,19 @@ 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
40- return set_tmlerr (new_tmlerr (L , DECODE_DEFINED_IDX ), false, 18 , "key is not a table" );
39+ TMLErr * err = new_tmlerr (L , DECODE_DEFINED_IDX );
40+ set_tmlerr (err , false, 29 , "key is not a table! Key was: " );
41+ return err_push_keys (L , err , keys_start , keys_start + keys_len - 1 );
4142 }
4243 lua_remove (L , parent_idx );
4344 // 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
4445 lua_pushvalue (L , -1 );
4546 lua_rawget (L , DECODE_DEFINED_IDX );
46- // TODO: print keys
47- if (lua_tointeger (L , -1 ) == -2 ) return set_tmlerr (new_tmlerr (L , DECODE_DEFINED_IDX ), false, 36 , "Keys may not redefine inline tables!" );
47+ if (lua_tointeger (L , -1 ) == -2 ) {
48+ TMLErr * err = new_tmlerr (L , DECODE_DEFINED_IDX );
49+ set_tmlerr (err , false, 46 , "Keys may not redefine inline tables! Key was: " );
50+ return err_push_keys (L , err , keys_start , keys_start + keys_len - 1 );
51+ }
4852 lua_pop (L , 1 );
4953 lua_pushvalue (L , -1 );
5054 lua_pushinteger (L , -1 );
@@ -54,8 +58,9 @@ static inline bool set_kv(lua_State *L, int keys_len, int value_idx) {
5458 lua_pushvalue (L , -2 );
5559 lua_rawget (L , -2 );
5660 if (!lua_isnil (L , -1 )) {
57- // TODO: print keys
58- return set_tmlerr (new_tmlerr (L , DECODE_DEFINED_IDX ), false, 20 , "key already defined!" );
61+ TMLErr * err = new_tmlerr (L , DECODE_DEFINED_IDX );
62+ set_tmlerr (err , false, 30 , "key already defined! Key was: " );
63+ return err_push_keys (L , err , keys_start , keys_start + keys_len - 1 );
5964 }
6065 lua_pop (L , 1 );
6166
@@ -68,7 +73,7 @@ static inline bool set_kv(lua_State *L, int keys_len, int value_idx) {
6873}
6974
7075// pops keys, leaves new root on top
71- static inline bool heading_nav (lua_State * L , int keys_len , bool array_type ) {
76+ static bool heading_nav (lua_State * L , int keys_len , bool array_type ) {
7277 if (keys_len <= 0 ) return set_tmlerr (new_tmlerr (L , DECODE_DEFINED_IDX ), false, 28 , "no keys provided to navigate" );
7378 int keys_start = absindex (lua_gettop (L ), - keys_len );
7479 lua_pushvalue (L , DECODE_RESULT_IDX );
@@ -84,8 +89,9 @@ static inline bool heading_nav(lua_State *L, int keys_len, bool array_type) {
8489 lua_pushvalue (L , -2 );
8590 lua_rawset (L , parent_idx ); // t[key] = new table
8691 } else if (vtype != LUA_TTABLE ) {
87- // TODO: print keys
88- return set_tmlerr (new_tmlerr (L , DECODE_DEFINED_IDX ), false, 33 , "cannot navigate through non-table" );
92+ TMLErr * err = new_tmlerr (L , DECODE_DEFINED_IDX );
93+ set_tmlerr (err , false, 44 , "cannot navigate through non-table! Key was: " );
94+ return err_push_keys (L , err , keys_start , keys_start + keys_len - 1 );
8995 }
9096 lua_remove (L , parent_idx ); // remove parent table, keep child on top
9197 lua_pushvalue (L , -1 );
@@ -106,8 +112,9 @@ static inline bool heading_nav(lua_State *L, int keys_len, bool array_type) {
106112 lua_rawseti (L , parent_idx , len );
107113 lua_remove (L , parent_idx ); // remove parent table, keep child on top
108114 } else if (len != 0 ) {
109- // TODO: print keys
110- return set_tmlerr (new_tmlerr (L , DECODE_DEFINED_IDX ), false, 22 , "table already defined!" );
115+ TMLErr * err = new_tmlerr (L , DECODE_DEFINED_IDX );
116+ set_tmlerr (err , false, 32 , "table already defined! Key was: " );
117+ return err_push_keys (L , err , keys_start , keys_start + keys_len - 1 );
111118 } else {
112119 lua_pushvalue (L , -1 );
113120 lua_pushinteger (L , -1 );
@@ -116,9 +123,11 @@ static inline bool heading_nav(lua_State *L, int keys_len, bool array_type) {
116123 } else if (len > 0 ) { // it was an array, grab latest
117124 lua_rawgeti (L , -1 , len );
118125 lua_remove (L , -2 );
119- if (!lua_istable (L , -1 ))
120- // TODO: print keys
121- return set_tmlerr (new_tmlerr (L , DECODE_DEFINED_IDX ), false, 33 , "cannot navigate through non-table" );
126+ if (!lua_istable (L , -1 )) {
127+ TMLErr * err = new_tmlerr (L , DECODE_DEFINED_IDX );
128+ set_tmlerr (err , false, 44 , "cannot navigate through non-table! Key was: " );
129+ return err_push_keys (L , err , keys_start , keys_start + keys_len - 1 );
130+ }
122131 }
123132 }
124133 lua_insert (L , keys_start );
@@ -169,14 +178,20 @@ int tomlua_decode(lua_State *L) {
169178 int keys_len = parse_keys (L , & src , & scratch , int_keys , DECODE_DEFINED_IDX );
170179 if (!keys_len ) goto fail ;
171180 if (!iter_starts_with (& src , "]]" , 2 )) {
172- // TODO: print keys
173- set_tmlerr (new_tmlerr (L , DECODE_DEFINED_IDX ), false, 30 , "table heading must end with ]]" );
181+ TMLErr * err = new_tmlerr (L , DECODE_DEFINED_IDX );
182+ set_tmlerr (err , false, 14 , "array heading " );
183+ int top = lua_gettop (L );
184+ err_push_keys (L , err , absindex (top , - keys_len ), top );
185+ tmlerr_push_str (err , " must end with ]]" , 17 );
174186 goto fail ;
175187 }
176188 iter_skip_n (& src , 2 ); // consume ]]
177189 if (!consume_whitespace_to_line (& src )) {
178- // TODO: print keys
179- set_tmlerr (new_tmlerr (L , DECODE_DEFINED_IDX ), false, 56 , "array [[headers]] must have a new line before new values" );
190+ TMLErr * err = new_tmlerr (L , DECODE_DEFINED_IDX );
191+ set_tmlerr (err , false, 8 , "array [[" );
192+ int top = lua_gettop (L );
193+ err_push_keys (L , err , absindex (top , - keys_len ), top );
194+ tmlerr_push_str (err , "]] must have a new line before new values" , 41 );
180195 goto fail ;
181196 }
182197 if (!heading_nav (L , keys_len , true)) goto fail ;
@@ -186,14 +201,20 @@ int tomlua_decode(lua_State *L) {
186201 int keys_len = parse_keys (L , & src , & scratch , int_keys , DECODE_DEFINED_IDX );
187202 if (!keys_len ) goto fail ;
188203 if (iter_peek (& src ).v != ']' ) {
189- // TODO: print keys
190- set_tmlerr (new_tmlerr (L , DECODE_DEFINED_IDX ), false, 29 , "table heading must end with ]" );
204+ TMLErr * err = new_tmlerr (L , DECODE_DEFINED_IDX );
205+ set_tmlerr (err , false, 14 , "table heading " );
206+ int top = lua_gettop (L );
207+ err_push_keys (L , err , absindex (top , - keys_len ), top );
208+ tmlerr_push_str (err , " must end with ]" , 16 );
191209 goto fail ;
192210 }
193211 iter_skip (& src ); // consume ]
194212 if (!consume_whitespace_to_line (& src )) {
195- // TODO: print keys
196- set_tmlerr (new_tmlerr (L , DECODE_DEFINED_IDX ), false, 54 , "table [headers] must have a new line before new values" );
213+ TMLErr * err = new_tmlerr (L , DECODE_DEFINED_IDX );
214+ set_tmlerr (err , false, 7 , "table [" );
215+ int top = lua_gettop (L );
216+ err_push_keys (L , err , absindex (top , - keys_len ), top );
217+ tmlerr_push_str (err , "] must have a new line before new values" , 40 );
197218 goto fail ;
198219 }
199220 if (!heading_nav (L , keys_len , false)) goto fail ;
@@ -203,14 +224,19 @@ int tomlua_decode(lua_State *L) {
203224 int keys_len = parse_keys (L , & src , & scratch , int_keys , DECODE_DEFINED_IDX );
204225 if (!keys_len ) goto fail ;
205226 if (iter_peek (& src ).v != '=' ) {
206- // TODO: print keys
207- set_tmlerr (new_tmlerr (L , DECODE_DEFINED_IDX ), false, 35 , "keys for assignment must end with =" );
227+ TMLErr * err = new_tmlerr (L , DECODE_DEFINED_IDX );
228+ set_tmlerr (err , false, 20 , "keys for assignment " );
229+ int top = lua_gettop (L );
230+ err_push_keys (L , err , absindex (top , - keys_len ), top );
231+ tmlerr_push_str (err , " must end with =" , 16 );
208232 goto fail ;
209233 }
210234 iter_skip (& src ); // consume =
211235 if (consume_whitespace_to_line (& src )) {
212- // TODO: print keys
213- 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!" );
236+ TMLErr * err = new_tmlerr (L , DECODE_DEFINED_IDX );
237+ set_tmlerr (err , false, 86 , "the value in key = value expressions must begin on the same line as the key! Key was: " );
238+ int top = lua_gettop (L );
239+ err_push_keys (L , err , absindex (top , - keys_len ), top );
214240 goto fail ;
215241 }
216242 if (!decode_inline_value (L , & src , & scratch , uopts , DECODE_DEFINED_IDX )) goto fail ;
0 commit comments