Skip to content

Commit 1d6538c

Browse files
committed
Merge branch 'utility/function-definitions'
2 parents 4b26110 + ac0393e commit 1d6538c

File tree

5 files changed

+34
-35
lines changed

5 files changed

+34
-35
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
set(DEPS_DIR "${laco_SOURCE_DIR}/deps")
22

3-
include_directories("${DEPS_DIR}/linenoise")
3+
include_directories("${laco_SOURCE_DIR}/src" "${DEPS_DIR}/linenoise")
44

55
set(SOURCE ${DEPS_DIR}/linenoise/linenoise.c
66
main.c util.c util/print.c

src/util.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "linenoise.h"
1111
#include "commands.h"
1212
#include "laco.h"
13-
#include "util/print.h"
1413

1514
/* Check if line is incomplete */
1615
static 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);

src/util.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ void laco_handle_line(struct LacoState* laco);
2929
*/
3030
void 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+
3250
int laco_is_match(const char** matches, const char* test_string);
3351

3452
#endif /* LACO_UTIL_H */

src/util/print.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
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 */
911
inline 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);

src/util/print.h

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)