1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-02-11 14:44:07 +00:00

Initial supported for scripted ingredients, not fully tested.

This adds a few additional interface functions, to be defined in:
scripts/global/cooking.lua, or
_mods/XYZ/scripts/cooking.lua

Added functions:
cookFailure(a,b,c) - Called when no recipe could be found for ingredients a,b,c
getIngredientString() - Called by the menu. Expected to return effects description
                        for scripted ingredient..
useIngredient(name) - Called when a scripted ingredient will be eaten.
                      Return true to eat.

Use a line like this in ingredients.txt:
LuaLoaf sealoaf Loaf (script)
to enable calling useIngredient() upon eating.
This commit is contained in:
fgenesis 2013-06-20 04:49:20 +02:00
parent 61395779a1
commit 1bbd9e097d
8 changed files with 250 additions and 88 deletions

View file

@ -61,7 +61,7 @@ bool Continuity::isIngredientFull(IngredientData *data)
{ {
if (nocasecmp(ingredients[i]->name, data->name)==0) if (nocasecmp(ingredients[i]->name, data->name)==0)
{ {
if (ingredients[i]->amount >= MAX_INGREDIENT_AMOUNT) if (ingredients[i]->amount >= ingredients[i]->maxAmount)
return true; return true;
else else
return false; return false;
@ -70,22 +70,23 @@ bool Continuity::isIngredientFull(IngredientData *data)
return false; return false;
} }
void Continuity::pickupIngredient(IngredientData *d, int amount, bool effects) void Continuity::pickupIngredient(IngredientData *d, int amount, bool effects, bool learn)
{ {
learnRecipe(d->name, effects); if(learn)
learnRecipe(d->name, effects);
if (!getIngredientHeldByName(d->name)) if (!getIngredientHeldByName(d->name))
{ {
ingredients.push_back(d); ingredients.push_back(d);
} }
if (d->amount < MAX_INGREDIENT_AMOUNT - amount) if (d->amount < d->maxAmount - amount)
{ {
d->amount += amount; d->amount += amount;
} }
else else
{ {
d->amount = MAX_INGREDIENT_AMOUNT; d->amount = d->maxAmount;
} }
} }
@ -607,8 +608,10 @@ std::string Continuity::getAllIEString(IngredientData *data)
return os.str(); return os.str();
} }
void Continuity::applyIngredientEffects(IngredientData *data) // returns true if eaten
bool Continuity::applyIngredientEffects(IngredientData *data)
{ {
bool eaten = true;
float y =0; float y =0;
for (int i = 0; i < data->effects.size(); i++) for (int i = 0; i < data->effects.size(); i++)
{ {
@ -841,28 +844,36 @@ void Continuity::applyIngredientEffects(IngredientData *data)
// this item should only affect li if naija drops it and li eats it. // this item should only affect li if naija drops it and li eats it.
} }
break; break;
case IET_SCRIPT:
{
// If this fails, it will still be eaten
if(dsq->game->cookingScript)
dsq->game->cookingScript->call("useIngredient", data->name.c_str(), &eaten);
}
default: default:
{ {
char str[256]; char str[256];
sprintf((char*)&str, "ingredient effect not defined, index[%d]", int(useType)); sprintf((char*)&str, "ingredient effect not defined, index[%d]", int(useType));
errorLog(str); errorLog(str);
eaten = false;
} }
break; break;
} }
} }
return eaten;
} }
std::string Continuity::getIngredientAffectsString(IngredientData *data) std::string Continuity::getIngredientAffectsString(IngredientData *data)
{ {
if(data->type == IET_SCRIPT)
/*
std::string str;
for (int i = 0; i < data->effects.size(); i++)
{ {
str += splitCamelCase(getIngredientDescription(data->effects[i].type)) + "\n"; if(dsq->game->cookingScript)
{
std::string ret = "";
dsq->game->cookingScript->call("getIngredientString", data->name.c_str(), &ret);
return ret;
}
} }
return str;
*/
return getAllIEString(data); return getAllIEString(data);
} }
@ -920,6 +931,7 @@ void Continuity::loadIngredientData(const std::string &file)
InStream in(file.c_str()); InStream in(file.c_str());
bool recipes = false; bool recipes = false;
bool extradata = false;
while (std::getline(in, line)) while (std::getline(in, line))
{ {
std::istringstream inLine(line); std::istringstream inLine(line);
@ -931,6 +943,11 @@ void Continuity::loadIngredientData(const std::string &file)
recipes = true; recipes = true;
break; break;
} }
else if(name == "==Extra==")
{
extradata = true;
break;
}
inLine >> gfx >> type; inLine >> gfx >> type;
std::getline(inLine, effects); std::getline(inLine, effects);
@ -944,7 +961,7 @@ void Continuity::loadIngredientData(const std::string &file)
if (p1 != std::string::npos && p2 != std::string::npos) if (p1 != std::string::npos && p2 != std::string::npos)
{ {
effects = effects.substr(p1+1, p2-(p1+1)); effects = effects.substr(p1+1, p2-(p1+1));
std::istringstream fxLine(effects); SimpleIStringStream fxLine(effects.c_str(), SimpleIStringStream::REUSE);
std::string bit; std::string bit;
while (fxLine >> bit) while (fxLine >> bit)
{ {
@ -1032,6 +1049,10 @@ void Continuity::loadIngredientData(const std::string &file)
{ {
fx.type = IET_LI; fx.type = IET_LI;
} }
else if (bit.find("script") != std::string::npos)
{
fx.type = IET_SCRIPT;
}
int c = 0; int c = 0;
while (c < bit.size()) while (c < bit.size())
@ -1052,6 +1073,31 @@ void Continuity::loadIngredientData(const std::string &file)
ingredientData.push_back(data); ingredientData.push_back(data);
} }
if(extradata)
{
while (in >> line)
{
SimpleIStringStream inLine(line.c_str(), SimpleIStringStream::REUSE);
int maxAmount = MAX_INGREDIENT_AMOUNT;
int rotKind = 1;
inLine >> name >> maxAmount >> rotKind;
if (name == "==Recipes==")
{
recipes = true;
continue;
}
IngredientData *data = getIngredientDataByName(name);
if(!data)
{
errorLog("Specifying data for undefined ingredient: " + name);
continue;
}
data->maxAmount = maxAmount;
data->rotKind = rotKind;
}
}
if (recipes) if (recipes)
{ {
bool quitNext = false; bool quitNext = false;

View file

@ -685,6 +685,7 @@ enum IngredientEffectType
IET_POISON = 17, IET_POISON = 17,
IET_BLIND = 18, IET_BLIND = 18,
IET_ALLSTATUS = 19, IET_ALLSTATUS = 19,
IET_SCRIPT = 20,
IET_MAX IET_MAX
}; };
@ -715,9 +716,11 @@ public:
std::string displayName; std::string displayName;
const IngredientType type; const IngredientType type;
int amount; int amount;
int maxAmount;
int held; int held;
int marked; int marked;
bool sorted; bool sorted;
bool rotKind;
bool hasIET(IngredientEffectType iet); bool hasIET(IngredientEffectType iet);
typedef std::vector<IngredientEffect> IngredientEffects; typedef std::vector<IngredientEffect> IngredientEffects;
@ -1051,7 +1054,7 @@ public:
std::string getSongNameBySlot(int slot); std::string getSongNameBySlot(int slot);
void toggleLiCombat(bool t); void toggleLiCombat(bool t);
void pickupIngredient(IngredientData *i, int amount, bool effects=true); void pickupIngredient(IngredientData *i, int amount, bool effects=true, bool learn=true);
int indexOfIngredientData(const IngredientData* data) const; int indexOfIngredientData(const IngredientData* data) const;
IngredientData *getIngredientHeldByName(const std::string &name) const; // an ingredient that the player actually has; in the ingredients list IngredientData *getIngredientHeldByName(const std::string &name) const; // an ingredient that the player actually has; in the ingredients list
IngredientData *getIngredientDataByName(const std::string &name); // an ingredient in the general data list; ingredientData IngredientData *getIngredientDataByName(const std::string &name); // an ingredient in the general data list; ingredientData
@ -1059,7 +1062,7 @@ public:
IngredientData *getIngredientHeldByIndex(int idx) const; IngredientData *getIngredientHeldByIndex(int idx) const;
IngredientData *getIngredientDataByIndex(int idx); IngredientData *getIngredientDataByIndex(int idx);
void applyIngredientEffects(IngredientData *data); bool applyIngredientEffects(IngredientData *data);
void loadIngredientData(const std::string &file); void loadIngredientData(const std::string &file);
void loadIngredientDisplayNames(const std::string& file); void loadIngredientDisplayNames(const std::string& file);

View file

@ -394,7 +394,7 @@ void FoodSlot::refresh(bool effects)
{ {
std::ostringstream os; std::ostringstream os;
if (i->amount > 1) if (i->amount > 1)
os << i->amount << "/" << MAX_INGREDIENT_AMOUNT; os << i->amount << "/" << i->maxAmount;
label->setText(os.str()); label->setText(os.str());
setTexture("Ingredients/" + i->gfx); setTexture("Ingredients/" + i->gfx);
renderQuad = true; renderQuad = true;
@ -456,10 +456,13 @@ void FoodSlot::eatMe()
if (!ingredient->effects.empty()) if (!ingredient->effects.empty())
{ {
ingredient->amount--; bool eaten = dsq->continuity.applyIngredientEffects(ingredient);
dsq->continuity.applyIngredientEffects(ingredient); if(eaten)
dsq->continuity.removeEmptyIngredients(); {
dsq->game->refreshFoodSlots(true); ingredient->amount--;
dsq->continuity.removeEmptyIngredients();
dsq->game->refreshFoodSlots(true);
}
} }
else else
{ {
@ -533,7 +536,7 @@ void FoodSlot::onUpdate(float dt)
Vector wp = getWorldPosition(); Vector wp = getWorldPosition();
if ((dsq->game->lips->getWorldPosition() - getWorldPosition()).isLength2DIn(32)) if ((dsq->game->lips->getWorldPosition() - wp).isLength2DIn(32))
{ {
dsq->menuSelectDelay = 0.5; dsq->menuSelectDelay = 0.5;
@ -548,7 +551,7 @@ void FoodSlot::onUpdate(float dt)
bool droppedIn = false; bool droppedIn = false;
for (int i = 0; i < foodHolders.size(); i++) for (int i = 0; i < foodHolders.size(); i++)
{ {
bool in = (foodHolders[i]->getWorldPosition() - getWorldPosition()).isLength2DIn(32); bool in = (foodHolders[i]->getWorldPosition() - wp).isLength2DIn(32);
if (in) if (in)
{ {
droppedIn = true; droppedIn = true;
@ -587,11 +590,6 @@ void FoodSlot::onUpdate(float dt)
label->alpha = 1; label->alpha = 1;
grabTime = 0; grabTime = 0;
if (dsq->inputMode == INPUT_JOYSTICK)
{
dsq->game->adjustFoodSlotCursor();
}
return; return;
} }
else else
@ -1236,6 +1234,8 @@ Game::Game() : StateObject()
lastCollideMaskIndex = -1; lastCollideMaskIndex = -1;
worldPaused = false; worldPaused = false;
cookingScript = 0;
} }
Game::~Game() Game::~Game()
@ -5836,41 +5836,6 @@ float Game::getHalfTimer(float mod)
return halfTimer*mod; return halfTimer*mod;
} }
void Game::adjustFoodSlotCursor()
{
// using visible slots now, don't need this atm
return;
/*
for (int i = 0; i < foodSlots.size(); i++)
{
if (foodSlots[i]->isCursorIn())
{
if (!foodSlots[i]->getIngredient() || foodSlots[i]->getIngredient()->amount <= 0)
{
foodSlots[i]->setFocus(false);
i--;
while (i >= 0)
{
if (foodSlots[i]->getIngredient() && foodSlots[i]->getIngredient()->amount > 0)
{
//cursor->position = foodSlots[i]->getWorldPosition();
foodSlots[i]->setFocus(true);
break;
}
i--;
}
if (i <= -1)
{
menu[5]->setFocus(true);
//cursor->position = menu[5]->getWorldPosition();
}
}
break;
}
}
*/
}
void Game::action(int id, int state) void Game::action(int id, int state)
{ {
for (int i = 0; i < paths.size(); i++) for (int i = 0; i < paths.size(); i++)
@ -5994,7 +5959,6 @@ void Game::action(int id, int state)
if (foodSlots[i]->isCursorIn() && foodSlots[i]->getIngredient()) if (foodSlots[i]->isCursorIn() && foodSlots[i]->getIngredient())
{ {
foodSlots[i]->moveRight(); foodSlots[i]->moveRight();
adjustFoodSlotCursor();
break; break;
} }
} }
@ -6031,7 +5995,6 @@ void Game::action(int id, int state)
if (ingrIndex >= 0) if (ingrIndex >= 0)
{ {
foodSlots[ingrIndex]->discard(); foodSlots[ingrIndex]->discard();
adjustFoodSlotCursor();
} }
} }
} }
@ -6709,6 +6672,14 @@ void Game::applyState()
musicToPlay = overrideMusic; musicToPlay = overrideMusic;
} }
if(cookingScript)
dsq->scriptInterface.closeScript(cookingScript);
if (dsq->mod.isActive())
cookingScript = dsq->scriptInterface.openScript(dsq->mod.getPath() + "scripts/cooking.lua", true);
else
cookingScript = dsq->scriptInterface.openScript("scripts/global/cooking.lua", true);
//INFO: this used to be here to start fading out the music //INFO: this used to be here to start fading out the music
// before the level had begun // before the level had begun
/* /*
@ -7244,7 +7215,20 @@ void Game::onCook()
if (r) if (r)
data = dsq->continuity.getIngredientDataByName(r->result); data = dsq->continuity.getIngredientDataByName(r->result);
else else if(cookingScript)
{
const char *p1 = cookList[0]->name.c_str();
const char *p2 = cookList[1]->name.c_str();
const char *p3 = cookList.size() >= 3 ? cookList[2]->name.c_str() : "";
std::string ingname;
cookingScript->call("cookFailure", p1, p2, p3, &ingname);
if(ingname.length())
data = dsq->continuity.getIngredientDataByName(ingname);
if(!data)
goto endcook;
}
if(!data)
{ {
dsq->sound->playSfx("Denied"); dsq->sound->playSfx("Denied");
data = dsq->continuity.getIngredientDataByName("SeaLoaf"); data = dsq->continuity.getIngredientDataByName("SeaLoaf");
@ -7424,6 +7408,8 @@ void Game::onCook()
} }
refreshFoodSlots(true); refreshFoodSlots(true);
endcook:
AquariaGuiElement::canDirMoveGlobal = true; AquariaGuiElement::canDirMoveGlobal = true;
isCooking = false; isCooking = false;
@ -8740,7 +8726,6 @@ void Game::refreshFoodSlots(bool effects)
{ {
foodSlots[i]->refresh(effects); foodSlots[i]->refresh(effects);
} }
adjustFoodSlotCursor();
} }
void Game::refreshTreasureSlots() void Game::refreshTreasureSlots()

View file

@ -714,6 +714,8 @@ public:
Ingredient *getNearestIngredient(const Vector &pos, int radius); Ingredient *getNearestIngredient(const Vector &pos, int radius);
Entity *getNearestEntity(const Vector &pos, int radius, Entity *ignore = 0, EntityType et=ET_NOTYPE, DamageType dt=DT_NONE, int lrStart=-1, int lrEnd=-1); Entity *getNearestEntity(const Vector &pos, int radius, Entity *ignore = 0, EntityType et=ET_NOTYPE, DamageType dt=DT_NONE, int lrStart=-1, int lrEnd=-1);
Script *cookingScript;
void spawnManaBall(Vector pos, float a); void spawnManaBall(Vector pos, float a);
bool updateMusic(); bool updateMusic();
std::string overrideMusic; std::string overrideMusic;

View file

@ -22,8 +22,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "Avatar.h" #include "Avatar.h"
IngredientData::IngredientData(const std::string &name, const std::string &gfx, IngredientType type) IngredientData::IngredientData(const std::string &name, const std::string &gfx, IngredientType type)
: name(name), gfx(gfx), amount(0), held(0), type(type), marked(0), sorted(false) : name(name), gfx(gfx), amount(0), maxAmount(MAX_INGREDIENT_AMOUNT), held(0), type(type), marked(0), sorted(false)
, displayName(dsq->continuity.getIngredientDisplayName(name)) , displayName(dsq->continuity.getIngredientDisplayName(name))
, rotKind(type == IT_OIL || type == IT_EGG)
{ {
} }
@ -83,15 +84,7 @@ void Ingredient::destroy()
bool Ingredient::isRotKind() bool Ingredient::isRotKind()
{ {
if (data) return data && data->rotKind;
{
if (data->type == IT_OIL || data->type == IT_EGG)
{
return false;
}
return true;
}
return false;
} }
IngredientData *Ingredient::getIngredientData() IngredientData *Ingredient::getIngredientData()

View file

@ -3578,10 +3578,10 @@ void SceneEditor::update(float dt)
(dsq->getGameCursorPosition().y - cursorOffset.y)*factor); (dsq->getGameCursorPosition().y - cursorOffset.y)*factor);
//editingElement->scale=oldScale + add; //editingElement->scale=oldScale + add;
Vector sz = oldScale + add; Vector sz = oldScale + add;
if (sz.x < 64) if (sz.x < 32)
sz.x = 64; sz.x = 32;
if (sz.y < 64) if (sz.y < 32)
sz.y = 64; sz.y = 32;
editingPath->rect.x1 = -sz.x/2; editingPath->rect.x1 = -sz.x/2;
editingPath->rect.x2 = sz.x/2; editingPath->rect.x2 = sz.x/2;
editingPath->rect.y1 = -sz.y/2; editingPath->rect.y1 = -sz.y/2;

View file

@ -76,6 +76,7 @@ static const char * const interfaceFunctions[] = {
"activate", "activate",
"animationKey", "animationKey",
"castSong", "castSong",
"cookFailure",
"damage", "damage",
"deathNotify", "deathNotify",
"dieEaten", "dieEaten",
@ -84,6 +85,7 @@ static const char * const interfaceFunctions[] = {
"entityDied", "entityDied",
"exitState", "exitState",
"exitTimer", "exitTimer",
"getIngredientString",
"hitEntity", "hitEntity",
"hitSurface", "hitSurface",
"init", "init",
@ -98,6 +100,7 @@ static const char * const interfaceFunctions[] = {
"songNoteDone", "songNoteDone",
"sporesDropped", "sporesDropped",
"update", "update",
"useIngredient",
"useTreasure", "useTreasure",
NULL NULL
}; };
@ -2997,11 +3000,6 @@ luaFunc(entity_followPath)
luaReturnNil(); luaReturnNil();
} }
luaFunc(getIngredientGfx)
{
luaReturnStr(dsq->continuity.getIngredientGfx(getString(L, 1)).c_str());
}
luaFunc(spawnIngredient) luaFunc(spawnIngredient)
{ {
int times = lua_tonumber(L, 4); int times = lua_tonumber(L, 4);
@ -6728,6 +6726,13 @@ luaFunc(ing_hasIET)
luaReturnBool(has); luaReturnBool(has);
} }
luaFunc(ing_getIngredientName)
{
Ingredient *i = getIng(L, 1);
IngredientData *data = i ? i->getIngredientData() : 0;
luaReturnStr(data ? data->name.c_str() : "");
}
luaFunc(entity_getNearestEntity) luaFunc(entity_getNearestEntity)
{ {
Entity *me = entity(L); Entity *me = entity(L);
@ -7704,6 +7709,82 @@ luaFunc(getScreenSize)
luaReturnVec2(core->width, core->height); luaReturnVec2(core->width, core->height);
} }
luaFunc(inv_isFull)
{
IngredientData *data = dsq->continuity.getIngredientDataByName(getString(L, 1));
bool full = false;
if(data)
full = dsq->continuity.isIngredientFull(data);
luaReturnBool(full);
}
luaFunc(inv_getMaxAmount)
{
IngredientData *data = dsq->continuity.getIngredientDataByName(getString(L, 1));
luaReturnInt(data ? data->maxAmount : 0);
}
luaFunc(inv_getAmount)
{
IngredientData *data = dsq->continuity.getIngredientDataByName(getString(L, 1));
luaReturnInt(data ? data->amount : 0);
}
luaFunc(inv_add)
{
IngredientData *data = dsq->continuity.getIngredientDataByName(getString(L, 1));
if(data)
dsq->continuity.pickupIngredient(data, lua_tointeger(L, 2), false, false);
luaReturnNil();
}
luaFunc(inv_getGfx)
{
luaReturnStr(dsq->continuity.getIngredientGfx(getString(L, 1)).c_str());
}
luaFunc(inv_remove)
{
IngredientData *data = dsq->continuity.getIngredientDataByName(getString(L, 1));
if(data && data->amount > 0)
{
data->amount--;
dsq->game->dropIngrNames.push_back(data->name);
dsq->continuity.removeEmptyIngredients();
if(dsq->game->isInGameMenu())
dsq->game->refreshFoodSlots(true);
}
luaReturnNil();
}
luaFunc(inv_getType)
{
IngredientData *data = dsq->continuity.getIngredientDataByName(getString(L, 1));
luaReturnInt(data ? data->type : 0);
}
luaFunc(inv_getDisplayName)
{
IngredientData *data = dsq->continuity.getIngredientDataByName(getString(L, 1));
luaReturnStr(data ? data->displayName.c_str() : "");
}
luaFunc(inv_pickupEffect)
{
IngredientData *data = dsq->continuity.getIngredientDataByName(getString(L, 1));
if(data)
dsq->game->pickupIngredientEffects(data);
luaReturnNil();
}
luaFunc(learnRecipe)
{
std::string name = getString(L, 1);
bool show = getBool(L, 2);
dsq->continuity.learnRecipe(name, show);
luaReturnNil();
}
luaFunc(createDebugText) luaFunc(createDebugText)
{ {
DebugFont *txt = new DebugFont(lua_tointeger(L, 2), getString(L, 1)); DebugFont *txt = new DebugFont(lua_tointeger(L, 2), getString(L, 1));
@ -7876,6 +7957,7 @@ static const struct {
luaRegister(reconstructEntityGrid), luaRegister(reconstructEntityGrid),
luaRegister(ing_hasIET), luaRegister(ing_hasIET),
luaRegister(ing_getIngredientName),
luaRegister(esetv), luaRegister(esetv),
luaRegister(esetvf), luaRegister(esetvf),
@ -8196,8 +8278,6 @@ static const struct {
luaRegister(registerSporeDrop), luaRegister(registerSporeDrop),
luaRegister(getIngredientGfx),
luaRegister(spawnIngredient), luaRegister(spawnIngredient),
luaRegister(spawnAllIngredients), luaRegister(spawnAllIngredients),
luaRegister(spawnParticleEffect), luaRegister(spawnParticleEffect),
@ -8690,6 +8770,17 @@ static const struct {
luaRegister(getScreenVirtualOff), luaRegister(getScreenVirtualOff),
luaRegister(getScreenSize), luaRegister(getScreenSize),
luaRegister(inv_isFull),
luaRegister(inv_getMaxAmount),
luaRegister(inv_getAmount),
luaRegister(inv_add),
luaRegister(inv_getGfx),
luaRegister(inv_remove),
luaRegister(inv_getType),
luaRegister(inv_getDisplayName),
luaRegister(inv_pickupEffect),
luaRegister(learnRecipe),
luaRegister(createDebugText), luaRegister(createDebugText),
luaRegister(createBitmapText), luaRegister(createBitmapText),
luaRegister(text_setText), luaRegister(text_setText),
@ -8746,6 +8837,7 @@ static const struct {
{"entity_rotateTo", l_entity_rotate}, {"entity_rotateTo", l_entity_rotate},
{"entity_setColor", l_entity_color}, {"entity_setColor", l_entity_color},
{"entity_setInternalOffset", l_entity_internalOffset}, {"entity_setInternalOffset", l_entity_internalOffset},
{"getIngredientGfx", l_inv_getGfx},
{"bone_setColor", l_bone_color}, {"bone_setColor", l_bone_color},
@ -9972,6 +10064,41 @@ bool Script::call(const char *name, void *param1, void *param2, void *param3, fl
return true; return true;
} }
bool Script::call(const char *name, const char *param, bool *ret)
{
lookupFunc(name);
lua_pushstring(L, param);
if (!doCall(1, 1))
return false;
*ret = lua_toboolean(L, -1);
lua_pop(L, 1);
return true;
}
bool Script::call(const char *name, const char *param, std::string *ret)
{
lookupFunc(name);
lua_pushstring(L, param);
if (!doCall(1, 1))
return false;
*ret = getString(L, -1);
lua_pop(L, 1);
return true;
}
bool Script::call(const char *name, const char *param1, const char *param2, const char *param3, std::string *ret)
{
lookupFunc(name);
lua_pushstring(L, param1);
lua_pushstring(L, param2);
lua_pushstring(L, param3);
if (!doCall(3, 1))
return false;
*ret = getString(L, -1);
lua_pop(L, 1);
return true;
}
int Script::callVariadic(const char *name, lua_State *fromL, int nparams, void *param) int Script::callVariadic(const char *name, lua_State *fromL, int nparams, void *param)
{ {
int oldtop = lua_gettop(L); int oldtop = lua_gettop(L);

View file

@ -60,6 +60,12 @@ public:
bool call(const char *name, void *param1, void *param2, void *param3, void *param4); bool call(const char *name, void *param1, void *param2, void *param3, void *param4);
// boolean = function(pointer, pointer, pointer, number, number, number, number, pointer) // boolean = function(pointer, pointer, pointer, number, number, number, number, pointer)
bool call(const char *name, void *param1, void *param2, void *param3, float param4, float param5, float param6, float param7, void *param8, bool *ret1); bool call(const char *name, void *param1, void *param2, void *param3, float param4, float param5, float param6, float param7, void *param8, bool *ret1);
// boolean = function(string)
bool call(const char *name, const char *param, bool *ret);
// string = function(string)
bool call(const char *name, const char *param, std::string *ret);
// string = function(string, string, string)
bool call(const char *name, const char *param1, const char *param2, const char *param3, std::string *ret);
// function(pointer, ...) - anything that is already on the stack is forwarded. Results are left on the stack. // function(pointer, ...) - anything that is already on the stack is forwarded. Results are left on the stack.
// Returns how many values the called function returned, or -1 in case of error. // Returns how many values the called function returned, or -1 in case of error.
int callVariadic(const char *name, lua_State *L, int nparams, void *param); int callVariadic(const char *name, lua_State *L, int nparams, void *param);