Created
May 26, 2013 15:36
-
-
Save hustlijian/5653137 to your computer and use it in GitHub Desktop.
a lua c api sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include "lua5.1/lua.h" | |
#include "lua5.1/lauxlib.h" | |
#include "lua5.1/lualib.h" | |
int main(void) | |
{ | |
char buff[256]; | |
int error; | |
lua_State *L = luaL_newstate(); | |
luaL_openlibs(L); | |
while(fgets(buff,sizeof(buff),stdin)!=NULL) | |
{ | |
error = luaL_loadbuffer(L, buff, strlen(buff), "line"); | |
lua_pcall(L,0,0,0); | |
if (error) { | |
fprintf(stderr, "%s", lua_tostring(L, -1)); | |
lua_pop(L, 1); | |
} | |
} | |
lua_close(L); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: | |
gcc -o capi capi.c -llua5.1 | |
clean: | |
rm -rvf capi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is a lua c api sample
enviroment:
system: ubuntu 12.04
lua: lua5.1