#include "luasys.h"
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "delay.h"
#include "led.h"
const char __stdin_name[150];
const char __stdout_name[150];
const char __stderr_name[150];
FILEHANDLE _sys_open(const char *name,int openmode)
{
return 0;
}
int _sys_close(FILEHANDLE fh)
{
return 0;
}
int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
{
return 0;
}
int _sys_read(FILEHANDLE fh, unsigned char*buf, unsigned len, int mode)
{
return 0;
}
//¼ì²é¾ä±úÊÇ·ñΪÖÕ¶Ë
int _sys_istty(FILEHANDLE fh)
{
return 0;
}
int _sys_seek(FILEHANDLE fh, long pos)
{
return 0;
}
//ˢоä±ú¹ØÁªµÄ»º³åÇø
int _sys_ensure(FILEHANDLE fh)
{
return 0;
}
//·µ»ØÎļþµ±Ç°³¤¶È
long _sys_flen(FILEHANDLE fh)
{
return 0;
}
void _sys_exit(int status)
{
//while(1);
}
int _sys_tmpnam(char *name, int fileno, unsigned maxlength)
{
return 0;
}
//½«Ò»¸ö×Ö·ûдÈë¿ØÖÆÌ¨
void _ttywrch(int ch)
{
}
int remove(const char *filename)
{
return 0;
}
char *_sys_command_string(char *cmd, int len)
{
return NULL;
}
static int lua_led_on(lua_State *L)
{
//PCout(13) = 1;
led_on();
return 1;
}
static int lua_led_off(lua_State *L)
{
//PCout(13) = 0;
led_off();
return 1;
}
static int lua_delay(lua_State *L)
{
int num;
num = lua_tointeger(L, 1);
Delay(num);
return 1;
}
static const struct luaL_Reg mylib[]=
{
{"led_on",lua_led_on},
{"led_off",lua_led_off},
{"delay",lua_delay},
{NULL,NULL}
};
char cmd1[] =" \
off = 10000 \
on = 10000 \
while 1 do \
led_on() \
delay(off) \
led_off() \
delay(on) \
end";
char kk[]="\
led_off()";
void lua_process()
{
while(1)
{
lua_State *L;
L = luaL_newstate(); /* ½¨Á¢LuaÔËÐл·¾³ */
luaopen_base(L);
luaL_setfuncs(L, mylib, 0);
luaL_dostring(L, cmd1);
while (1);
}
}