#include "shrink.h" #include "LuaDriverFuns.h" #ifdef _UCOS OS_STK LuaTaskStk[LuaTaskStkLengh]; struct luainfo li; const char printstr[] = { "printbuf = \"\" \n" "function print(...)\n" "for i,v in ipairs(arg) do\n" "printbuf = printbuf .. tostring(v)\n" "end\n" "printbuf = printbuf .. \"\\n\"\n" "end\n" }; int i; void LuaParse(void* pdata) { int n; uint8 err; int error; const char * buf; lua_State *L; char *p; while(1) { n = 0; //sem_wait(pcf->cgisem,0,&err); sem_wait(li.luasem,0,&err); L = lua_open(); luaopen_base(L); /* opens the basic library */ luaopen_table(L); /* opens the table library */ //luaopen_io(L); /* opens the I/O library */ luaopen_string(L); /* opens the string lib. */ luaopen_math(L); /* opens the math lib. */ //luaL_openlibs(L); lua_register(L,"LedSwitch",LedSwitch); /*注册驱动函数*/ lua_register(L,"CpuStat",CpuStat); //lua_register(L,"ADCGET",ADCGET); error = luaL_loadbuffer(L, printstr, strlen(printstr),"printstr") || lua_pcall(L, 0, 0, 0); if (error) { lua_pop(L,1); } p = li.env; /*把环境变量加入L*/ while(*p != NULL) { error = luaL_loadbuffer(L, p, strlen(p),"") || lua_pcall(L, 0, 0, 0); if (error) { lua_pop(L,1); } p = strchr(p,'\0'); p ++; } error = luaL_loadbuffer(L, li.cgifile, strlen(li.cgifile),"") || lua_pcall(L, 0, 0, 0); if (error) { lua_pop(L,1); } lua_getglobal(L,"printbuf"); buf = lua_tostring(L,-1); n += _snprintf(li.iobuf+n, IO_REMOTE-n, "%s", buf); lua_close(L); sem_post(li.wssem); } } #endif