aboutsummaryrefslogtreecommitdiffstats
path: root/luaing.c
diff options
context:
space:
mode:
Diffstat (limited to 'luaing.c')
-rw-r--r--luaing.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/luaing.c b/luaing.c
index ac08668..3086921 100644
--- a/luaing.c
+++ b/luaing.c
@@ -1,3 +1,12 @@
+/*
+ * 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>
@@ -6,20 +15,18 @@
int main(int argc, char **argv)
{
- char buffer[256];
- int error;
- lua_State *L = luaL_newstate();
- luaL_openlibs(L);
+ char buffer[256];
- while (fgets(buffer, sizeof(buffer), stdin) != NULL) {
- error = luaL_loadbuffer(L, buffer, strlen(buffer), "line")
- || lua_pcall(L, 0, 0, 0);
- if (error) {
- fprintf(stderr, "%s", lua_tostring(L, -1));
- lua_pop(L, 1);
- }
- }
+ lua_State *state = luaL_newstate();
+ luaL_openlibs(state);
- lua_close(L);
- return 0;
+ 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;
}