make constants in the lua api's a lot easier to write

This commit is contained in:
jacob1
2013-06-05 22:56:00 -04:00
parent 875ca75b07
commit c7ce3fa4b2
2 changed files with 108 additions and 109 deletions

View File

@@ -492,28 +492,28 @@ void LuaScriptInterface::initSimulationAPI()
lua_setglobal(l, "sim"); lua_setglobal(l, "sim");
//Static values //Static values
lua_pushinteger(l, XRES); lua_setfield(l, simulationAPI, "XRES"); SETCONST(l, XRES);
lua_pushinteger(l, YRES); lua_setfield(l, simulationAPI, "YRES"); SETCONST(l, YRES);
lua_pushinteger(l, PT_NUM); lua_setfield(l, simulationAPI, "PT_NUM"); SETCONST(l, PT_NUM);
lua_pushinteger(l, luacon_sim->NUM_PARTS); lua_setfield(l, simulationAPI, "NUM_PARTS"); lua_pushinteger(l, luacon_sim->NUM_PARTS); lua_setfield(l, simulationAPI, "NUM_PARTS");
lua_pushinteger(l, R_TEMP); lua_setfield(l, simulationAPI, "R_TEMP"); SETCONST(l, R_TEMP);
lua_pushinteger(l, MAX_TEMP); lua_setfield(l, simulationAPI, "MAX_TEMP"); SETCONST(l, MAX_TEMP);
lua_pushinteger(l, MIN_TEMP); lua_setfield(l, simulationAPI, "MIN_TEMP"); SETCONST(l, MIN_TEMP);
lua_pushinteger(l, TOOL_HEAT); lua_setfield(l, simulationAPI, "TOOL_HEAT"); SETCONST(l, TOOL_HEAT);
lua_pushinteger(l, TOOL_COOL); lua_setfield(l, simulationAPI, "TOOL_COOL"); SETCONST(l, TOOL_COOL);
lua_pushinteger(l, TOOL_VAC); lua_setfield(l, simulationAPI, "TOOL_VAC"); SETCONST(l, TOOL_VAC);
lua_pushinteger(l, TOOL_AIR); lua_setfield(l, simulationAPI, "TOOL_AIR"); SETCONST(l, TOOL_AIR);
lua_pushinteger(l, TOOL_PGRV); lua_setfield(l, simulationAPI, "TOOL_PGRV"); SETCONST(l, TOOL_PGRV);
lua_pushinteger(l, TOOL_NGRV); lua_setfield(l, simulationAPI, "TOOL_NGRV"); SETCONST(l, TOOL_NGRV);
lua_pushinteger(l, luacon_sim->tools.size()); lua_setfield(l, simulationAPI, "TOOL_WIND"); lua_pushinteger(l, luacon_sim->tools.size()); lua_setfield(l, simulationAPI, "TOOL_WIND");
lua_pushinteger(l, DECO_DRAW); lua_setfield(l, simulationAPI, "DECO_DRAW"); SETCONST(l, DECO_DRAW);
lua_pushinteger(l, DECO_CLEAR); lua_setfield(l, simulationAPI, "DECO_CLEAR"); SETCONST(l, DECO_CLEAR);
lua_pushinteger(l, DECO_ADD); lua_setfield(l, simulationAPI, "DECO_ADD"); SETCONST(l, DECO_ADD);
lua_pushinteger(l, DECO_SUBTRACT); lua_setfield(l, simulationAPI, "DECO_SUBTRACT"); SETCONST(l, DECO_SUBTRACT);
lua_pushinteger(l, DECO_MULTIPLY); lua_setfield(l, simulationAPI, "DECO_MULTIPLY"); SETCONST(l, DECO_MULTIPLY);
lua_pushinteger(l, DECO_DIVIDE); lua_setfield(l, simulationAPI, "DECO_DIVIDE"); SETCONST(l, DECO_DIVIDE);
lua_pushinteger(l, DECO_SMUDGE); lua_setfield(l, simulationAPI, "DECO_SMUDGE"); SETCONST(l, DECO_SMUDGE);
//Declare FIELD_BLAH constants //Declare FIELD_BLAH constants
std::vector<StructProperty> particlePropertiesV = Particle::GetProperties(); std::vector<StructProperty> particlePropertiesV = Particle::GetProperties();
@@ -1527,55 +1527,53 @@ void LuaScriptInterface::initRendererAPI()
lua_getglobal(l, "renderer"); lua_getglobal(l, "renderer");
lua_setglobal(l, "ren"); lua_setglobal(l, "ren");
int rendererAPI = lua_gettop(l);
//Static values //Static values
//Particle pixel modes/fire mode/effects //Particle pixel modes/fire mode/effects
lua_pushinteger(l, PMODE); lua_setfield(l, rendererAPI, "PMODE"); SETCONST(l, PMODE);
lua_pushinteger(l, PMODE_NONE); lua_setfield(l, rendererAPI, "PMODE_NONE"); SETCONST(l, PMODE_NONE);
lua_pushinteger(l, PMODE_FLAT); lua_setfield(l, rendererAPI, "PMODE_FLAT"); SETCONST(l, PMODE_FLAT);
lua_pushinteger(l, PMODE_BLOB); lua_setfield(l, rendererAPI, "PMODE_BLOB"); SETCONST(l, PMODE_BLOB);
lua_pushinteger(l, PMODE_BLUR); lua_setfield(l, rendererAPI, "PMODE_BLUR"); SETCONST(l, PMODE_BLUR);
lua_pushinteger(l, PMODE_GLOW); lua_setfield(l, rendererAPI, "PMODE_GLOW"); SETCONST(l, PMODE_GLOW);
lua_pushinteger(l, PMODE_SPARK); lua_setfield(l, rendererAPI, "PMODE_SPARK"); SETCONST(l, PMODE_SPARK);
lua_pushinteger(l, PMODE_FLARE); lua_setfield(l, rendererAPI, "PMODE_FLARE"); SETCONST(l, PMODE_FLARE);
lua_pushinteger(l, PMODE_LFLARE); lua_setfield(l, rendererAPI, "PMODE_LFLARE"); SETCONST(l, PMODE_LFLARE);
lua_pushinteger(l, PMODE_ADD); lua_setfield(l, rendererAPI, "PMODE_ADD"); SETCONST(l, PMODE_ADD);
lua_pushinteger(l, PMODE_BLEND); lua_setfield(l, rendererAPI, "PMODE_BLEND"); SETCONST(l, PMODE_BLEND);
lua_pushinteger(l, PSPEC_STICKMAN); lua_setfield(l, rendererAPI, "PSPEC_STICKMAN"); SETCONST(l, PSPEC_STICKMAN);
lua_pushinteger(l, OPTIONS); lua_setfield(l, rendererAPI, "OPTIONS"); SETCONST(l, OPTIONS);
lua_pushinteger(l, NO_DECO); lua_setfield(l, rendererAPI, "NO_DECO"); SETCONST(l, NO_DECO);
lua_pushinteger(l, DECO_FIRE); lua_setfield(l, rendererAPI, "DECO_FIRE"); SETCONST(l, DECO_FIRE);
lua_pushinteger(l, FIREMODE); lua_setfield(l, rendererAPI, "FIREMODE"); SETCONST(l, FIREMODE);
lua_pushinteger(l, FIRE_ADD); lua_setfield(l, rendererAPI, "FIRE_ADD"); SETCONST(l, FIRE_ADD);
lua_pushinteger(l, FIRE_BLEND); lua_setfield(l, rendererAPI, "FIRE_BLEND"); SETCONST(l, FIRE_BLEND);
lua_pushinteger(l, EFFECT); lua_setfield(l, rendererAPI, "EFFECT"); SETCONST(l, EFFECT);
lua_pushinteger(l, EFFECT_GRAVIN); lua_setfield(l, rendererAPI, "EFFECT_GRAVIN"); SETCONST(l, EFFECT_GRAVIN);
lua_pushinteger(l, EFFECT_GRAVOUT); lua_setfield(l, rendererAPI, "EFFECT_GRAVOUT"); SETCONST(l, EFFECT_GRAVOUT);
lua_pushinteger(l, EFFECT_LINES); lua_setfield(l, rendererAPI, "EFFECT_LINES"); SETCONST(l, EFFECT_LINES);
lua_pushinteger(l, EFFECT_DBGLINES); lua_setfield(l, rendererAPI, "EFFECT_DBGLINES"); SETCONST(l, EFFECT_DBGLINES);
//Display/Render/Colour modes //Display/Render/Colour modes
lua_pushinteger(l, RENDER_EFFE); lua_setfield(l, rendererAPI, "RENDER_EFFE"); SETCONST(l, RENDER_EFFE);
lua_pushinteger(l, RENDER_FIRE); lua_setfield(l, rendererAPI, "RENDER_FIRE"); SETCONST(l, RENDER_FIRE);
lua_pushinteger(l, RENDER_GLOW); lua_setfield(l, rendererAPI, "RENDER_GLOW"); SETCONST(l, RENDER_GLOW);
lua_pushinteger(l, RENDER_BLUR); lua_setfield(l, rendererAPI, "RENDER_BLUR"); SETCONST(l, RENDER_BLUR);
lua_pushinteger(l, RENDER_BLOB); lua_setfield(l, rendererAPI, "RENDER_BLOB"); SETCONST(l, RENDER_BLOB);
lua_pushinteger(l, RENDER_BASC); lua_setfield(l, rendererAPI, "RENDER_BASC"); SETCONST(l, RENDER_BASC);
lua_pushinteger(l, RENDER_NONE); lua_setfield(l, rendererAPI, "RENDER_NONE"); SETCONST(l, RENDER_NONE);
lua_pushinteger(l, COLOUR_HEAT); lua_setfield(l, rendererAPI, "COLOUR_HEAT"); SETCONST(l, COLOUR_HEAT);
lua_pushinteger(l, COLOUR_LIFE); lua_setfield(l, rendererAPI, "COLOUR_LIFE"); SETCONST(l, COLOUR_LIFE);
lua_pushinteger(l, COLOUR_GRAD); lua_setfield(l, rendererAPI, "COLOUR_GRAD"); SETCONST(l, COLOUR_GRAD);
lua_pushinteger(l, COLOUR_BASC); lua_setfield(l, rendererAPI, "COLOUR_BASC"); SETCONST(l, COLOUR_BASC);
lua_pushinteger(l, COLOUR_DEFAULT); lua_setfield(l, rendererAPI, "COLOUR_DEFAULT"); SETCONST(l, COLOUR_DEFAULT);
lua_pushinteger(l, DISPLAY_AIRC); lua_setfield(l, rendererAPI, "DISPLAY_AIRC"); SETCONST(l, DISPLAY_AIRC);
lua_pushinteger(l, DISPLAY_AIRP); lua_setfield(l, rendererAPI, "DISPLAY_AIRP"); SETCONST(l, DISPLAY_AIRP);
lua_pushinteger(l, DISPLAY_AIRV); lua_setfield(l, rendererAPI, "DISPLAY_AIRV"); SETCONST(l, DISPLAY_AIRV);
lua_pushinteger(l, DISPLAY_AIRH); lua_setfield(l, rendererAPI, "DISPLAY_AIRH"); SETCONST(l, DISPLAY_AIRH);
lua_pushinteger(l, DISPLAY_AIR); lua_setfield(l, rendererAPI, "DISPLAY_AIR"); SETCONST(l, DISPLAY_AIR);
lua_pushinteger(l, DISPLAY_WARP); lua_setfield(l, rendererAPI, "DISPLAY_WARP"); SETCONST(l, DISPLAY_WARP);
lua_pushinteger(l, DISPLAY_PERS); lua_setfield(l, rendererAPI, "DISPLAY_PERS"); SETCONST(l, DISPLAY_PERS);
lua_pushinteger(l, DISPLAY_EFFE); lua_setfield(l, rendererAPI, "DISPLAY_EFFE"); SETCONST(l, DISPLAY_EFFE);
} }
//get/set render modes list //get/set render modes list
@@ -1723,48 +1721,48 @@ void LuaScriptInterface::initElementsAPI()
//Static values //Static values
//Element types/properties/states //Element types/properties/states
lua_pushinteger(l, TYPE_PART); lua_setfield(l, elementsAPI, "TYPE_PART"); SETCONST(l, TYPE_PART);
lua_pushinteger(l, TYPE_LIQUID); lua_setfield(l, elementsAPI, "TYPE_LIQUID"); SETCONST(l, TYPE_LIQUID);
lua_pushinteger(l, TYPE_SOLID); lua_setfield(l, elementsAPI, "TYPE_SOLID"); SETCONST(l, TYPE_SOLID);
lua_pushinteger(l, TYPE_GAS); lua_setfield(l, elementsAPI, "TYPE_GAS"); SETCONST(l, TYPE_GAS);
lua_pushinteger(l, TYPE_ENERGY); lua_setfield(l, elementsAPI, "TYPE_ENERGY"); SETCONST(l, TYPE_ENERGY);
lua_pushinteger(l, PROP_CONDUCTS); lua_setfield(l, elementsAPI, "PROP_CONDUCTS"); SETCONST(l, PROP_CONDUCTS);
lua_pushinteger(l, PROP_BLACK); lua_setfield(l, elementsAPI, "PROP_BLACK"); SETCONST(l, PROP_BLACK);
lua_pushinteger(l, PROP_NEUTPENETRATE); lua_setfield(l, elementsAPI, "PROP_NEUTPENETRATE"); SETCONST(l, PROP_NEUTPENETRATE);
lua_pushinteger(l, PROP_NEUTABSORB); lua_setfield(l, elementsAPI, "PROP_NEUTABSORB"); SETCONST(l, PROP_NEUTABSORB);
lua_pushinteger(l, PROP_NEUTPASS); lua_setfield(l, elementsAPI, "PROP_NEUTPASS"); SETCONST(l, PROP_NEUTPASS);
lua_pushinteger(l, PROP_DEADLY); lua_setfield(l, elementsAPI, "PROP_DEADLY"); SETCONST(l, PROP_DEADLY);
lua_pushinteger(l, PROP_HOT_GLOW); lua_setfield(l, elementsAPI, "PROP_HOT_GLOW"); SETCONST(l, PROP_HOT_GLOW);
lua_pushinteger(l, PROP_LIFE); lua_setfield(l, elementsAPI, "PROP_LIFE"); SETCONST(l, PROP_LIFE);
lua_pushinteger(l, PROP_RADIOACTIVE); lua_setfield(l, elementsAPI, "PROP_RADIOACTIVE"); SETCONST(l, PROP_RADIOACTIVE);
lua_pushinteger(l, PROP_LIFE_DEC); lua_setfield(l, elementsAPI, "PROP_LIFE_DEC"); SETCONST(l, PROP_LIFE_DEC);
lua_pushinteger(l, PROP_LIFE_KILL); lua_setfield(l, elementsAPI, "PROP_LIFE_KILL"); SETCONST(l, PROP_LIFE_KILL);
lua_pushinteger(l, PROP_LIFE_KILL_DEC); lua_setfield(l, elementsAPI, "PROP_LIFE_KILL_DEC"); SETCONST(l, PROP_LIFE_KILL_DEC);
lua_pushinteger(l, PROP_SPARKSETTLE); lua_setfield(l, elementsAPI, "PROP_SPARKSETTLE"); SETCONST(l, PROP_SPARKSETTLE);
lua_pushinteger(l, PROP_NOAMBHEAT); lua_setfield(l, elementsAPI, "PROP_NOAMBHEAT"); SETCONST(l, PROP_NOAMBHEAT);
lua_pushinteger(l, FLAG_STAGNANT); lua_setfield(l, elementsAPI, "FLAG_STAGNANT"); SETCONST(l, FLAG_STAGNANT);
lua_pushinteger(l, FLAG_SKIPMOVE); lua_setfield(l, elementsAPI, "FLAG_SKIPMOVE"); SETCONST(l, FLAG_SKIPMOVE);
lua_pushinteger(l, FLAG_MOVABLE); lua_setfield(l, elementsAPI, "FLAG_MOVABLE"); SETCONST(l, FLAG_MOVABLE);
lua_pushinteger(l, ST_NONE); lua_setfield(l, elementsAPI, "ST_NONE"); SETCONST(l, ST_NONE);
lua_pushinteger(l, ST_SOLID); lua_setfield(l, elementsAPI, "ST_SOLID"); SETCONST(l, ST_SOLID);
lua_pushinteger(l, ST_LIQUID); lua_setfield(l, elementsAPI, "ST_LIQUID"); SETCONST(l, ST_LIQUID);
lua_pushinteger(l, ST_GAS); lua_setfield(l, elementsAPI, "ST_GAS"); SETCONST(l, ST_GAS);
lua_pushinteger(l, SC_WALL); lua_setfield(l, elementsAPI, "SC_WALL"); SETCONST(l, SC_WALL);
lua_pushinteger(l, SC_ELEC); lua_setfield(l, elementsAPI, "SC_ELEC"); SETCONST(l, SC_ELEC);
lua_pushinteger(l, SC_POWERED); lua_setfield(l, elementsAPI, "SC_POWERED"); SETCONST(l, SC_POWERED);
lua_pushinteger(l, SC_FORCE); lua_setfield(l, elementsAPI, "SC_FORCE"); SETCONST(l, SC_FORCE);
lua_pushinteger(l, SC_EXPLOSIVE); lua_setfield(l, elementsAPI, "SC_EXPLOSIVE"); SETCONST(l, SC_EXPLOSIVE);
lua_pushinteger(l, SC_GAS); lua_setfield(l, elementsAPI, "SC_GAS"); SETCONST(l, SC_GAS);
lua_pushinteger(l, SC_LIQUID); lua_setfield(l, elementsAPI, "SC_LIQUID"); SETCONST(l, SC_LIQUID);
lua_pushinteger(l, SC_POWDERS); lua_setfield(l, elementsAPI, "SC_POWDERS"); SETCONST(l, SC_POWDERS);
lua_pushinteger(l, SC_SOLIDS); lua_setfield(l, elementsAPI, "SC_SOLIDS"); SETCONST(l, SC_SOLIDS);
lua_pushinteger(l, SC_NUCLEAR); lua_setfield(l, elementsAPI, "SC_NUCLEAR"); SETCONST(l, SC_NUCLEAR);
lua_pushinteger(l, SC_SPECIAL); lua_setfield(l, elementsAPI, "SC_SPECIAL"); SETCONST(l, SC_SPECIAL);
lua_pushinteger(l, SC_LIFE); lua_setfield(l, elementsAPI, "SC_LIFE"); SETCONST(l, SC_LIFE);
lua_pushinteger(l, SC_TOOL); lua_setfield(l, elementsAPI, "SC_TOOL"); SETCONST(l, SC_TOOL);
lua_pushinteger(l, SC_DECO); lua_setfield(l, elementsAPI, "SC_DECO"); SETCONST(l, SC_DECO);
lua_pushinteger(l, SC_SENSOR); lua_setfield(l, elementsAPI, "SC_SENSOR"); SETCONST(l, SC_SENSOR);
//Element identifiers //Element identifiers
for(int i = 0; i < PT_NUM; i++) for(int i = 0; i < PT_NUM; i++)
@@ -2270,8 +2268,6 @@ void LuaScriptInterface::initVirtualMachineAPI()
//elem shortcut //elem shortcut
lua_getglobal(l, "virtualMachine"); lua_getglobal(l, "virtualMachine");
lua_setglobal(l, "vm"); lua_setglobal(l, "vm");
int vmAPI = lua_gettop(l);
} }
int LuaScriptInterface::virtualMachine_loadProgram(lua_State * l) int LuaScriptInterface::virtualMachine_loadProgram(lua_State * l)
@@ -2506,8 +2502,6 @@ void LuaScriptInterface::initFileSystemAPI()
//elem shortcut //elem shortcut
lua_getglobal(l, "fileSystem"); lua_getglobal(l, "fileSystem");
lua_setglobal(l, "fs"); lua_setglobal(l, "fs");
int fileSystemAPI = lua_gettop(l);
} }
int LuaScriptInterface::fileSystem_list(lua_State * l) int LuaScriptInterface::fileSystem_list(lua_State * l)

View File

@@ -37,6 +37,11 @@ class Tool;
#define LUACON_EL_MODIFIED_GRAPHICS 0x2 #define LUACON_EL_MODIFIED_GRAPHICS 0x2
#define LUACON_EL_MODIFIED_MENUS 0x4 #define LUACON_EL_MODIFIED_MENUS 0x4
// idea from mniip, makes things much simpler
#define SETCONST(L, NAME)\
lua_pushinteger(L, NAME);\
lua_setfield(L, -2, #NAME);
class TPTScriptInterface; class TPTScriptInterface;
class LuaScriptInterface: public CommandInterface class LuaScriptInterface: public CommandInterface
{ {