diff options
author | EliteTK <tomasz.kramkowski@gmail.com> | 2015-06-19 19:12:12 +0100 |
---|---|---|
committer | EliteTK <tomasz.kramkowski@gmail.com> | 2015-06-19 19:12:12 +0100 |
commit | da87fcf25e0c94e57f00df84679cd6fadc56ed46 (patch) | |
tree | 3c53eea9db01039990455af870a2ca65e7e5a123 /luaing.c | |
parent | 75d2e00662416224f4b745e0004f48f1fc1d9665 (diff) | |
parent | 7bf25fb8f0e4643a67894417a95d39e5901b1824 (diff) | |
download | c-stuff-da87fcf25e0c94e57f00df84679cd6fadc56ed46.tar.gz c-stuff-da87fcf25e0c94e57f00df84679cd6fadc56ed46.tar.xz c-stuff-da87fcf25e0c94e57f00df84679cd6fadc56ed46.zip |
Merge branch 'master' of https://github.com/EliteTK/c-stuff
Diffstat (limited to 'luaing.c')
-rw-r--r-- | luaing.c | 35 |
1 files changed, 21 insertions, 14 deletions
@@ -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; } |