aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2015-04-04 20:55:23 +0200
committerTomasz Kramkowski <tk@the-tk.com>2015-04-04 20:55:23 +0200
commitb1e025a502645cf4478d307708b7282cb834a7a8 (patch)
tree4c3f99634e88c59dea4c2530235173fe555a3f73
parentd4826bc768f9e66b02b8e1826ad849f549e24b90 (diff)
downloadc-stuff-b1e025a502645cf4478d307708b7282cb834a7a8.tar.gz
c-stuff-b1e025a502645cf4478d307708b7282cb834a7a8.tar.xz
c-stuff-b1e025a502645cf4478d307708b7282cb834a7a8.zip
luaing: minor cleanup.
-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;
}