#include “stdafx.h”
lua_State *L;
void load_lua(char *filename){
L=luaL_newstate();
luaL_openlibs(L);
if((luaL_loadfile(L,filename) || lua_pcall(L,0,0,0))!=0){
luaL_error(L,”loadfile error! \n %s”,lua_tostring(L,-1));
}
}
double getfield(lua_State *L,char * key){
double res;
//默认栈顶是table,将key入栈
lua_pushstring(L,key);
lua_gettable(L,-2); //查找键值为key的元素,置于栈顶
if(!lua_isnumber(L,-1)){
luaL_error(L,”num get error! %s\n”,lua_tostring(L,-1));
}
res=lua_tonumber(L,-1);
lua_pop(L,1); //删掉产生的查找结果
return res;
}
void setfield(lua_State *L,char *key,double value){
//默认栈顶是table
lua_pushstring(L,key);
lua_pushnumber(L,value);
lua_settable(L,-3); //将这一对键值设成元素
}
struct mycolor{
char *name;
unsigned char red,green,blue;
}Color[]={