2
Copyright (C) 2010-2011 wpitchoune@gmail.com
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
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21
#define _(str) gettext(str)
29
#include "plib_luatpl.h"
32
luatpl_generate(const char *lua,
33
int (*init) (lua_State *, void *),
35
struct luatpl_error *err)
42
err->code = LUATPL_ERROR_LUA_STATE_OPEN;
48
if (!init || init(L, init_data)) {
50
if (!luaL_loadfile(L, lua)) {
51
if (!lua_pcall(L, 0, 1, 0)) {
52
if (lua_isstring(L, -1))
53
page = strdup(lua_tostring(L, -1));
56
LUATPL_ERROR_WRONG_RETURN_TYPE;
58
err->code = LUATPL_ERROR_LUA_EXECUTION;
59
err->message = strdup(lua_tostring(L, -1));
62
err->code = LUATPL_ERROR_LUA_FILE_LOAD;
65
err->code = LUATPL_ERROR_INIT;
74
luatpl_generate_file(const char *lua,
75
int (*init) (lua_State *, void *),
78
struct luatpl_error *err)
86
content = luatpl_generate(lua, init, init_data, err);
89
f = fopen(dst_path, "w");
92
if (fputs(content, f) == EOF)
110
luatpl_fprint_error(FILE *stream,
111
const struct luatpl_error *err,
113
const char *dst_path)
115
if (!err || !err->code)
119
case LUATPL_ERROR_LUA_FILE_LOAD:
121
_("LUATPL Error: failed to load Lua script: %s.\n"),
125
case LUATPL_ERROR_INIT:
127
_("LUATPL Error: failed to call init function: %s.\n"),
131
case LUATPL_ERROR_LUA_EXECUTION:
134
"failed to execute Lua script (%s): %s.\n"),
138
case LUATPL_ERROR_WRONG_RETURN_TYPE:
141
"lua script (%s) returned a wrong type.\n"),
145
case LUATPL_ERROR_LUA_STATE_OPEN:
148
"failed to open lua state.\n"));
154
_("LUATPL Error: code: %d.\n"),