mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-01-24 17:26:41 +00:00
Add entity_v(), node_v() Lua functions
This commit is contained in:
parent
a3fb57fde9
commit
9229bb2c0a
6 changed files with 78 additions and 4 deletions
|
@ -724,6 +724,11 @@ void Path::luaDebugMsg(const std::string &func, const std::string &msg)
|
|||
debugLog("luaScriptError: Path [" + name + "]: " + func + " : " + msg);
|
||||
}
|
||||
|
||||
int Path::pushLuaVars(lua_State *L)
|
||||
{
|
||||
return script ? script->pushLocalVars(L) : 0;
|
||||
}
|
||||
|
||||
MinimapIcon *Path::ensureMinimapIcon()
|
||||
{
|
||||
if(!minimapIcon)
|
||||
|
|
|
@ -157,6 +157,7 @@ public:
|
|||
|
||||
int messageVariadic(lua_State *L, int nparams);
|
||||
void luaDebugMsg(const std::string &func, const std::string &msg);
|
||||
int pushLuaVars(lua_State *L);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -414,10 +414,22 @@ static void ensureType(lua_State *L, T *& ptr, ScriptObjectType ty)
|
|||
}
|
||||
}
|
||||
}
|
||||
template <typename T>
|
||||
static void ensureTypeNoError(lua_State *L, T *& ptr, ScriptObjectType ty)
|
||||
{
|
||||
if (ptr)
|
||||
{
|
||||
ScriptObject *so = (ScriptObject*)(ptr);
|
||||
if (!so->isType(ty))
|
||||
ptr = NULL;
|
||||
}
|
||||
}
|
||||
# define ENSURE_TYPE(ptr, ty) ensureType(L, (ptr), (ty))
|
||||
# define ENSURE_TYPE_NO_ERROR(ptr, ty) ensureTypeNoError(L, (ptr), (ty))
|
||||
# define typecheckOnly(func) func
|
||||
#else
|
||||
# define ENSURE_TYPE(ptr, ty)
|
||||
# define ENSURE_TYPE_NO_ERROR(ptr, ty)
|
||||
# define typecheckOnly(func)
|
||||
#endif
|
||||
|
||||
|
@ -441,6 +453,18 @@ ScriptedEntity *scriptedEntity(lua_State *L, int slot = 1)
|
|||
return se;
|
||||
}
|
||||
|
||||
static inline
|
||||
ScriptedEntity *scriptedEntityOpt(lua_State *L, int slot = 1)
|
||||
{
|
||||
ScriptedEntity *se = (ScriptedEntity*)lua_touserdata(L, slot);
|
||||
ENSURE_TYPE_NO_ERROR(se, SCO_SCRIPTED_ENTITY); // Dont't error if not ScriptedEntity...
|
||||
if (se)
|
||||
return se;
|
||||
|
||||
ENSURE_TYPE(se, SCO_ENTITY); // ... but error if not even Entity
|
||||
return NULL; // still return NULL
|
||||
}
|
||||
|
||||
static inline
|
||||
CollideEntity *collideEntity(lua_State *L, int slot = 1)
|
||||
{
|
||||
|
@ -708,14 +732,23 @@ static void safePath(lua_State *L, const std::string& path)
|
|||
#define luaReturnVec4(x,y,z,w) do {lua_pushnumber(L, (x)); lua_pushnumber(L, (y)); lua_pushnumber(L, (z)); lua_pushnumber(L, (w)); return 4;} while(0)
|
||||
#define luaReturnNil() return 0;
|
||||
|
||||
// Set the global "v" to the instance's local variable table. Must be
|
||||
// called when starting a script.
|
||||
static void fixupLocalVars(lua_State *L)
|
||||
static void pushLocalVarTab(lua_State *L, lua_State *Lv)
|
||||
{
|
||||
lua_getglobal(L, "_threadvars");
|
||||
lua_pushlightuserdata(L, L);
|
||||
// [_thv]
|
||||
lua_pushlightuserdata(L, Lv);
|
||||
// [_thv][L]
|
||||
lua_gettable(L, -2);
|
||||
// [_thv][v]
|
||||
lua_remove(L, -2);
|
||||
// [v]
|
||||
}
|
||||
|
||||
// Set the global "v" to the instance's local variable table. Must be
|
||||
// called when starting a script.
|
||||
static void fixupLocalVars(lua_State *L)
|
||||
{
|
||||
pushLocalVarTab(L, L);
|
||||
lua_setglobal(L, "v");
|
||||
}
|
||||
|
||||
|
@ -3003,6 +3036,19 @@ luaFunc(entity_getTargetPriority)
|
|||
luaReturnInt(e ? e->targetPriority : 0);
|
||||
}
|
||||
|
||||
// returns nil for non-scripted entities
|
||||
luaFunc(entity_v)
|
||||
{
|
||||
ScriptedEntity *se = scriptedEntityOpt(L);
|
||||
return se ? se->pushLuaVars(L) : 0;
|
||||
}
|
||||
|
||||
luaFunc(node_v)
|
||||
{
|
||||
Path *n = path(L);
|
||||
return n ? n->pushLuaVars(L) : 0;
|
||||
}
|
||||
|
||||
luaFunc(isQuitFlag)
|
||||
{
|
||||
luaReturnBool(dsq->isQuitFlag());
|
||||
|
@ -7894,6 +7940,11 @@ luaFunc(getNextFilteredEntity)
|
|||
return 2;
|
||||
}
|
||||
|
||||
// MISSING FOR ANDROID COMPAT
|
||||
//luaFunc(getEntityList)
|
||||
//luaFunc(entity_getEntityListInRange) // (me, range)
|
||||
//luaFunc(vector_getEntityListInRange) // (x, y, range)
|
||||
|
||||
luaFunc(getEntity)
|
||||
{
|
||||
Entity *ent = 0;
|
||||
|
@ -9802,6 +9853,9 @@ static const struct {
|
|||
|
||||
luaRegister(entity_setActivationType),
|
||||
|
||||
luaRegister(entity_v),
|
||||
luaRegister(node_v),
|
||||
|
||||
luaRegister(isQuitFlag),
|
||||
luaRegister(isDeveloperKeys),
|
||||
luaRegister(isDemo),
|
||||
|
@ -12007,3 +12061,9 @@ int Script::callVariadic(const char *name, lua_State *fromL, int nparams, void *
|
|||
|
||||
return nparams;
|
||||
}
|
||||
|
||||
int Script::pushLocalVars(lua_State *Ltarget)
|
||||
{
|
||||
pushLocalVarTab(Ltarget, L);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -72,6 +72,8 @@ public:
|
|||
// 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.
|
||||
int callVariadic(const char *name, lua_State *L, int nparams, void *param);
|
||||
// Pushes the entity's "v" table on top of the passed Lua stack. Returns number of things pushed (0 or 1)
|
||||
int pushLocalVars(lua_State *Ltarget);
|
||||
|
||||
lua_State *getLuaState() {return L;}
|
||||
const std::string &getFile() {return file;}
|
||||
|
|
|
@ -112,6 +112,11 @@ int ScriptedEntity::messageVariadic(lua_State *L, int nparams)
|
|||
return Entity::messageVariadic(L, nparams);
|
||||
}
|
||||
|
||||
int ScriptedEntity::pushLuaVars(lua_State *L)
|
||||
{
|
||||
return script ? script->pushLocalVars(L) : 0;
|
||||
}
|
||||
|
||||
void ScriptedEntity::warpSegments()
|
||||
{
|
||||
Segmented::warpSegments(position);
|
||||
|
|
|
@ -50,6 +50,7 @@ public:
|
|||
void entityDied(Entity *e);
|
||||
void message(const std::string &msg, int v);
|
||||
int messageVariadic(lua_State *L, int nparams);
|
||||
int pushLuaVars(lua_State *L);
|
||||
|
||||
static bool runningActivation;
|
||||
|
||||
|
|
Loading…
Reference in a new issue