File tree Expand file tree Collapse file tree 5 files changed +34
-35
lines changed Expand file tree Collapse file tree 5 files changed +34
-35
lines changed Original file line number Diff line number Diff line change 11set (DEPS_DIR "${laco_SOURCE_DIR} /deps" )
22
3- include_directories ("${DEPS_DIR} /linenoise" )
3+ include_directories ("${laco_SOURCE_DIR} /src" " ${ DEPS_DIR} /linenoise" )
44
55set (SOURCE ${DEPS_DIR} /linenoise/linenoise.c
66 main.c util.c util/print.c
Original file line number Diff line number Diff line change 1010#include "linenoise.h"
1111#include "commands.h"
1212#include "laco.h"
13- #include "util/print.h"
1413
1514/* Check if line is incomplete */
1615static bool incomplete (lua_State * L , int status ) {
@@ -138,12 +137,12 @@ void laco_handle_line(LacoState* laco) {
138137 status = lua_pcall (L , 0 , LUA_MULTRET , 0 );
139138 }
140139
141- laco_report_error (L , status );
140+ laco_report_error (laco , status );
142141
143142 if (status == 0 && lua_gettop (L ) > 0 ) {
144- status = laco_print_type (L );
143+ status = laco_print_type (laco );
145144
146- laco_report_error (L , status );
145+ laco_report_error (laco , status );
147146 }
148147
149148 laco_set_laco_status (laco , status );
Original file line number Diff line number Diff line change @@ -29,6 +29,24 @@ void laco_handle_line(struct LacoState* laco);
2929 */
3030void laco_kill (struct LacoState * laco , int status , const char * message );
3131
32+ /**
33+ * When there is a value on the lua stack, it will print out depending on
34+ * the type it is
35+ *
36+ * param pointer to LacoState
37+ *
38+ * return LUA_ERRSYNTAX if the value has some error
39+ */
40+ int laco_print_type (struct LacoState * laco );
41+
42+ /**
43+ * Prints out and pops off errors pushed into the lua stack
44+ *
45+ * param pointer to LacoState
46+ * param incoming lua stack status
47+ */
48+ void laco_report_error (struct LacoState * laco , int status );
49+
3250int laco_is_match (const char * * matches , const char * test_string );
3351
3452#endif /* LACO_UTIL_H */
Original file line number Diff line number Diff line change 1- #include "print .h"
1+ #include "util .h"
22
33#include <stdio.h>
44#include <stdbool.h>
55
66#include <lua.h>
77
8+ #include "laco.h"
9+
810/* C Wrapper for lua's tostring function */
911inline static const char * to_lua_string (lua_State * L ) {
1012 const char * result = NULL ;
@@ -78,9 +80,10 @@ static void print_table(lua_State* L) {
7880
7981/* External API*/
8082
81- int laco_print_type (lua_State * L ) {
82- int status = 0 ;
83- int luatype = lua_type (L , -1 );
83+ int laco_print_type (LacoState * laco ) {
84+ lua_State * L = laco_get_laco_lua_state (laco );
85+ int status = laco_get_laco_status (laco );
86+ int luatype = lua_type (L , -1 );
8487
8588 if (luatype != LUA_TTABLE ) {
8689 lua_getglobal (L , "print" );
@@ -91,10 +94,14 @@ int laco_print_type(lua_State* L) {
9194 print_table (L );
9295 }
9396
97+ laco_set_laco_status (laco , status );
98+
9499 return status ;
95100}
96101
97- void laco_report_error (lua_State * L , int status ) {
102+ void laco_report_error (LacoState * laco , int status ) {
103+ lua_State * L = laco_get_laco_lua_state (laco );
104+
98105 if (status != 0 && lua_isstring (L , -1 )) {
99106 fprintf (stderr , "%s\n" , lua_tostring (L , -1 ));
100107 fflush (stderr );
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments