当前位置: 技术问答>linux和unix
求教用过lua的大侠关于在C中嵌入lua脚本的连接问题?
来源: 互联网 发布时间:2015-12-16
本文导语: #include #include #include #include #include #include int main (){ char buff[256]; int error; lua_State *L=lua_open(); luaopen_base(L); luaopen_table(L); luaopen_io(L); ...
#include
#include
#include
#include
#include
#include
int main (){
char buff[256];
int error;
lua_State *L=lua_open();
luaopen_base(L);
luaopen_table(L);
luaopen_io(L);
luaopen_string(L);
luaopen_math(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;
}
源代码,不记得在哪引用的了
Makefile:
EXEC:=test
OBJC:=test.o
CC:=g++
$(EXEC):$(OBJC)
$(CC) -g $(OBJC) -o $(EXEC) -llua -L /home/xx/sms/lua/lua-5.1.1/lib/
$(OBJC):test.c
$(CC) -g -c test.c
clean:
rm -f *.o $(EXEC
/home/xx/sms/lua/lua-5.1.1/lib/下有liblua.a
#include
#include
#include
#include
#include
int main (){
char buff[256];
int error;
lua_State *L=lua_open();
luaopen_base(L);
luaopen_table(L);
luaopen_io(L);
luaopen_string(L);
luaopen_math(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;
}
源代码,不记得在哪引用的了
Makefile:
EXEC:=test
OBJC:=test.o
CC:=g++
$(EXEC):$(OBJC)
$(CC) -g $(OBJC) -o $(EXEC) -llua -L /home/xx/sms/lua/lua-5.1.1/lib/
$(OBJC):test.c
$(CC) -g -c test.c
clean:
rm -f *.o $(EXEC
/home/xx/sms/lua/lua-5.1.1/lib/下有liblua.a
|
.c文件就用gcc编译.