Implement lua scripts with support for standard and posix libraries.
2 * Copyright (C) 2009 J. Ali Harlow <ali@juiblex.co.uk>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <sys/types.h>
29 #include "razor-internal.h"
32 * This kludge is to work around an apparent bug in Fedora 10's lua package
33 * (it appears to require libm but not to include a DT_NEEDED).
36 void (*kludge)() = (void (*)())sin;
38 static void recursive_remove(const char *directory)
44 dp = opendir(directory);
45 while((dirp = readdir(dp))) {
46 if (strcmp(dirp->d_name, ".") && strcmp(dirp->d_name, "..")) {
47 buf = malloc(strlen(directory) + strlen(dirp->d_name)
49 sprintf(buf, "%s/%s", directory, dirp->d_name);
51 recursive_remove(buf);
59 int main(int argc, char *argv[])
61 char root[] = "/tmp/razor.XXXXXX";
69 fprintf(stderr, "usage: %s [TESTS-FILE]\n", argv[0]);
75 test_file = "test.lua";
82 s = malloc(strlen(root) + strlen("/testfile") + 1);
84 strcat(s, "/testfile");
90 fprintf(fp, "#!" LUA_BINARY "\n"
91 "print('Abracadabra!')\n");
92 fchmod(fileno(fp), S_IRUSR | S_IWUSR | S_IXUSR);
96 script = razor_file_get_contents(test_file, &len);
97 r = run_lua_script(root, test_file, script, len);
98 razor_file_free_contents(script, len);
100 recursive_remove(root);