aboutsummaryrefslogtreecommitdiffstats
path: root/luaing.c
blob: 3086921e45e083ccbc6d3234f851d92f40ccd479 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
 * Copyright (C) 2015  Tomasz Kramkowski <tk@the-tk.com>
 *
 * This program is free software. It is licensed under version 3 of the
 * GNU General Public License.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see [http://www.gnu.org/licenses/].
 */
#include <stdio.h>
#include <string.h>
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>

int main(int argc, char **argv)
{
	char buffer[256];

	lua_State *state = luaL_newstate();
	luaL_openlibs(state);

	while (fgets(buffer, sizeof(buffer), stdin) != NULL) {
		if (luaL_loadbuffer(state, buffer, strlen(buffer), "line") || lua_pcall(state, 0, 0, 0)) {
			fprintf(stderr, "%s", lua_tostring(state, -1));
			lua_pop(state, 1);
		}
	}

	lua_close(state);
	return 0;
}