File tree Expand file tree Collapse file tree 4 files changed +41
-13
lines changed Expand file tree Collapse file tree 4 files changed +41
-13
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ void laco_handle_command(struct LacoState* laco, char* line) {
3838 char * command_line = strdup (line + 1 );
3939 char * * command_words = laco_line_to_words (command_line );
4040
41- /* Alias for */
41+ /* Alias for parsed out words within the line */
4242 const char * command = command_words [0 ];
4343 const char * * arguments = (const char * * ) command_words + 1 ;
4444
Original file line number Diff line number Diff line change 11#include "debugger.h"
22
3- #include <stdio.h>
43#include <lua.h>
54
5+ #include <stdio.h>
6+ #include <stdlib.h>
7+ #include <string.h>
8+
69#include "laco.h"
10+ #include "util.h"
711
812void laco_print_debug_info (struct LacoState * laco ,
913 const char * function_name ) {
10- lua_State * L = laco_get_laco_lua_state (laco );
14+ int i ;
15+ char * namespace ;
16+ lua_State * L = laco_get_laco_lua_state (laco );
17+ size_t index = LUA_GLOBALSINDEX ;
1118 lua_Debug debug_info = {0 };
1219
13- lua_getfield (L , LUA_GLOBALSINDEX , function_name );
20+ char * name = strdup (function_name );
21+ char * * namespaces = laco_split_by ("." , name , 0 );
22+
23+ /* Walk down the namespace if there is something to go down */
24+ for (i = 0 ; (namespace = namespaces [i ]); i ++ ) {
25+ lua_getfield (L , index , namespace );
26+ index = lua_gettop (L );
27+ }
1428
1529 lua_getinfo (L , ">Sl" , & debug_info );
1630
@@ -21,4 +35,12 @@ void laco_print_debug_info(struct LacoState* laco,
2135 "Current line: \t%d\n" ,
2236 debug_info .what , debug_info .source ,
2337 debug_info .linedefined , debug_info .currentline );
38+
39+ /* Pop off the extra fields from the top of the stack */
40+ if (i > 1 ) {
41+ lua_pop (L , i - 1 );
42+ }
43+
44+ free (name );
45+ free (namespaces );
2446}
Original file line number Diff line number Diff line change @@ -100,10 +100,10 @@ static bool pushline(LacoState* laco, bool isFirstLine) {
100100 return result ;
101101}
102102
103- static inline void ignore_extra_spaces ( char * * string_ptr ) {
103+ static inline void ignore_extra ( const char chr , char * * string_ptr ) {
104104 if (* string_ptr == NULL ) return ;
105105
106- while (* * string_ptr == ' ' ) {
106+ while (* * string_ptr == chr ) {
107107 * string_ptr += 1 ;
108108 }
109109}
@@ -179,18 +179,19 @@ int laco_is_match(const char** matches, const char* test_string) {
179179 return false;
180180}
181181
182- char * * laco_line_to_words (char * line ) {
183- if (line == NULL ) return NULL ;
182+ char * * laco_split_by (const char * split_with , char * string ,
183+ int ignore_repeats ) {
184+ if (string == NULL ) return NULL ;
184185
185186 char * * result = calloc (16 , sizeof (char * ));
186187 size_t i = 0 ;
187188
188189 while (1 ) {
189- result [i ] = strsep (& line , " " );
190+ result [i ] = strsep (& string , split_with );
190191
191192 if (result [i ] == NULL ) break ;
192193
193- ignore_extra_spaces ( & line );
194+ if ( ignore_repeats ) ignore_extra ( split_with [ 0 ], & string );
194195
195196 i += 1 ;
196197 }
Original file line number Diff line number Diff line change @@ -39,9 +39,14 @@ void laco_report_error(struct LacoState* laco, int status);
3939int laco_is_match (const char * * matches , const char * test_string );
4040
4141/**
42- * Takes a line, seperated by spaces, and changes it into an array of the
43- * words that make up the line . The last value of this array will be NULL.
42+ * Break the provided string into an array of strings that are between the
43+ * split_with value . The last value of this array will be NULL.
4444 */
45- char * * laco_line_to_words (char * line );
45+ char * * laco_split_by (const char * split_with , char * string ,
46+ int ignore_repeats );
47+
48+ /* Macro for splitting with spaces */
49+ #define laco_line_to_words (line ) \
50+ laco_split_by(" ", line, 1)
4651
4752#endif /* LACO_UTIL_H */
You can’t perform that action at this time.
0 commit comments