added global variable handling to compiler context (not working yet because of case problems)

pull/7/head
Marc Zinnschlag 15 years ago
parent f9c1548f80
commit d57e67e722

@ -36,6 +36,7 @@ source_group(apps\\openmw\\mwinput FILES ${GAMEINPUT} ${GAMEINPUT_HEADER})
set(GAMESCRIPT
apps/openmw/mwscript/scriptmanager.cpp
apps/openmw/mwscript/compilercontext.cpp
apps/openmw/mwscript/interpretercontext.cpp
apps/openmw/mwscript/cellextensions.cpp
apps/openmw/mwscript/extensions.cpp

@ -180,7 +180,8 @@ void OMW::Engine::go()
MWScript::registerExtensions (mExtensions);
mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full);
mScriptContext = new MWScript::CompilerContext (MWScript::CompilerContext::Type_Full,
mEnvironment);
mScriptContext->setExtensions (&mExtensions);
mScriptManager = new MWScript::ScriptManager (mEnvironment.mWorld->getStore(), mVerboseScripts,

@ -0,0 +1,26 @@
#include "compilercontext.hpp"
#include "../mwworld/environment.hpp"
#include "../mwworld/world.hpp"
namespace MWScript
{
CompilerContext::CompilerContext (Type type, const MWWorld::Environment& environment)
: mType (type), mEnvironment (environment)
{}
bool CompilerContext::canDeclareLocals() const
{
return mType==Type_Full;
}
char CompilerContext::getGlobalType (const std::string& name) const
{
if (const ESM::Global *global = mEnvironment.mWorld->getStore().globals.find (name))
return global->type;
return ' ';
}
}

@ -3,6 +3,11 @@
#include <components/compiler/context.hpp>
namespace MWWorld
{
class Environment;
}
namespace MWScript
{
class CompilerContext : public Compiler::Context
@ -19,19 +24,17 @@ namespace MWScript
private:
Type mType;
const MWWorld::Environment& mEnvironment;
public:
CompilerContext (Type type) : mType (type) {}
CompilerContext (Type type, const MWWorld::Environment& environment);
// Is the compiler allowed to declare local variables?
virtual bool canDeclareLocals() const
{
return mType==Type_Full;
}
/// Is the compiler allowed to declare local variables?
virtual bool canDeclareLocals() const;
virtual char getGlobalType (const std::string& name) const { return ' '; }
///< 'l: long, 's': short, 'f': float, ' ': does not exist.
/// 'l: long, 's': short, 'f': float, ' ': does not exist.
virtual char getGlobalType (const std::string& name) const;
};
}

@ -11,7 +11,7 @@ namespace ESM {
struct Global
{
float value;
unsigned value;
VarType type;
void load(ESMReader &esm)
@ -24,8 +24,7 @@ struct Global
else esm.fail("Illegal global variable type " + tmp);
type = t;
// The value looks like a float in many cases, and like an integer
// in others (for the s type at least.) Figure it out.
// Note: Both floats and longs are represented as floats.
esm.getHNT(value, "FLTV");
}
};

Loading…
Cancel
Save