summaryrefslogtreecommitdiff
path: root/src/bindings.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bindings.c')
-rw-r--r--src/bindings.c45
1 files changed, 21 insertions, 24 deletions
diff --git a/src/bindings.c b/src/bindings.c
index 1a73fb0..5813d68 100644
--- a/src/bindings.c
+++ b/src/bindings.c
@@ -1,6 +1,7 @@
#include <stdlib.h>
#include <string.h>
#include <lua.h>
+#include <lauxlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -8,7 +9,6 @@
#include <errno.h>
#include <fcntl.h>
-#include "honeysuckle.h"
#include "md4c-html.h"
#include "bindings.h"
#include "logging.h"
@@ -50,8 +50,7 @@ static void md_callback(const MD_CHAR *html, MD_SIZE size, void *data)
int markdown(lua_State *L)
{
argent_log(TRACE, "begin markdown parsing");
- char *markdown_buffer;
- hs_parse_args(L, hs_str(markdown_buffer));
+ char *markdown_buffer = luaL_checkstring(L, 1);
size_t len = strlen(markdown_buffer);
argent_log(TRACE, "markdown input (%ld bytes): %s", len, markdown_buffer);
@@ -67,10 +66,10 @@ int markdown(lua_State *L)
// fill out the buffer
int error = md_html(markdown_buffer, len, md_callback, &data, md_flags, 0);
if (error)
- hs_throw_error(L, "markdown parsing failed!");
+ luaL_error(L, "markdown parsing failed!");
if (data.ok == false)
- hs_throw_error(L, "encountered error (re)allocating html buffer memory!");
+ luaL_error(L, "encountered error (re)allocating html buffer memory!");
data.buf[data.index] = 0;
@@ -103,8 +102,7 @@ static struct dirent *read_dir(lua_State *L, DIR *directory);
int scan_directory(lua_State *L)
{
argent_log(TRACE, "begin scan_directory()");
- char *dir_name;
- hs_parse_args(L, hs_str(dir_name));
+ char *dir_name = luaL_checkstring(L, 1);
DIR *directory = opendir(dir_name);
if (directory == NULL)
@@ -142,23 +140,23 @@ static void throw_directory_error(lua_State *L, char *dir_name)
argent_log(ERROR, "failed to open directory: %d\n", errno);
switch(errno) {
case EACCES:
- hs_throw_error(L, "read %s: permission denied", dir_name);
+ luaL_error(L, "read %s: permission denied", dir_name);
break;
case EMFILE:
- hs_throw_error(L, "read %s: this process has too many open files", dir_name);
+ luaL_error(L, "read %s: this process has too many open files", dir_name);
break;
case ENFILE:
- hs_throw_error(L, "read %s: this file system cannot support any more open files", dir_name);
+ luaL_error(L, "read %s: this file system cannot support any more open files", dir_name);
break;
case ENOMEM:
- hs_throw_error(L, "read %s: Not enough memory", dir_name);
+ luaL_error(L, "read %s: Not enough memory", dir_name);
break;
default:
- hs_throw_error(L, "read %s: unknown error", dir_name);
+ luaL_error(L, "read %s: unknown error", dir_name);
break;
}
}
@@ -173,7 +171,7 @@ static struct dirent *read_dir(lua_State *L, DIR *directory)
if (entry == NULL && errno != 0) {
argent_log(ERROR, "attempted to read invalid dirstream");
closedir(directory);
- hs_throw_error(L, "attempted to read invalid dirstream");
+ luaL_error(L, "attempted to read invalid dirstream");
}
return entry;
@@ -207,8 +205,7 @@ static const char* mkdir_error_string()
int create_directory(lua_State *L)
{
- char *dir_name;
- hs_parse_args(L, hs_str(dir_name));
+ char *dir_name = luaL_checkstring(L, 1);
mode_t mode = S_IRWXU | S_IRWXG | (S_IROTH | S_IXOTH); // u+rwx, g+rwx, a+rx
@@ -216,7 +213,7 @@ int create_directory(lua_State *L)
if (error) {
argent_log(ERROR, "failed to create directory '%s': %s",
dir_name, mkdir_error_string());
- hs_throw_error(L, "failed to create directory '%s': %s",
+ luaL_error(L, "failed to create directory '%s': %s",
dir_name, mkdir_error_string());
}
@@ -278,8 +275,8 @@ static const char* open_error_string()
int copy_file(lua_State *L)
{
- char *source_name, *dest_name;
- hs_parse_args(L, hs_str(source_name), hs_str(dest_name));
+ char *source_name = luaL_checkstring(L, 1);
+ char *dest_name = luaL_checkstring(L, 2);
int source_fd, dest_fd;
@@ -287,7 +284,7 @@ int copy_file(lua_State *L)
if (source_fd == -1) {
argent_log(ERROR, "failed to open file '%s': %s",
source_name, open_error_string());
- hs_throw_error(L, "failed to open file '%s': %s",
+ luaL_error(L, "failed to open file '%s': %s",
source_name, open_error_string());
}
@@ -297,7 +294,7 @@ int copy_file(lua_State *L)
close(source_fd);
argent_log(ERROR, "failed to stat '%s': %s",
source_name, open_error_string());
- hs_throw_error(L, "failed to stat '%s': %s",
+ luaL_error(L, "failed to stat '%s': %s",
source_name, open_error_string());
}
mode_t dest_mode = source_stat.st_mode;
@@ -306,7 +303,7 @@ int copy_file(lua_State *L)
close(source_fd);
argent_log(ERROR, "failed to open file '%s': %s",
dest_name, open_error_string());
- hs_throw_error(L, "failed to open file '%s': %s",
+ luaL_error(L, "failed to open file '%s': %s",
dest_name, open_error_string());
}
@@ -321,7 +318,7 @@ int copy_file(lua_State *L)
argent_log(ERROR, "failed to write to file '%s'", dest_name);
close(source_fd);
close(dest_fd);
- hs_throw_error(L, "failed to write to file '%s'", dest_name);
+ luaL_error(L, "failed to write to file '%s'", dest_name);
}
else {
write(dest_fd, buffer, bytes_read);
@@ -338,8 +335,8 @@ int copy_file(lua_State *L)
int argent_log_lua(lua_State *L)
{
- char *level_string, *message;
- hs_parse_args(L, hs_str(level_string), hs_str(message));
+ char *level_string = luaL_checkstring(L, 1);
+ char *message = luaL_checkstring(L, 2);
int level;