More scripting updates

git-svn-id: https://openmw.svn.sourceforge.net/svnroot/openmw/trunk@78 ea6a568a-9f4f-0410-981a-c910a81bb256
pull/7/head
nkorslund 16 years ago
parent 0d7b08cbae
commit 838d4f0ebe

@ -518,7 +518,13 @@ class NewExpression : Expression
{
// We need to find the index associated with this class, and
// pass it to the assembler.
clsInd = (cast(ObjectType)type).getClass().getIndex();
auto mc = (cast(ObjectType)type).getClass();
assert(mc !is null);
clsInd = mc.getIndex();
// Don't create instances of modules!
if(mc.isModule)
fail("Cannot create instances of modules", loc);
}
else if(type.isArray)
{

@ -635,9 +635,9 @@ class FuncDeclaration : Statement
{
// Validate all types (make sure there are no dangling forward
// references)
fn.type.validate();
fn.type.validate(fn.name.loc);
foreach(p; fn.params)
p.type.validate();
p.type.validate(fn.name.loc);
if(code !is null)
code.resolve(sc);

@ -231,7 +231,7 @@ abstract class Type : Block
// Validate that this type actually exists. This is used to make
// sure that all forward references are resolved.
void validate() {}
void validate(Floc loc) {}
// Check if this type is equivalent to the given D type
final bool isDType(TypeInfo ti)
@ -777,7 +777,7 @@ class ObjectType : Type
clsIndex = mc.gIndex;
}
MonsterClass getClass()
MonsterClass getClass(Floc loc = Floc.init)
{
assert(clsIndex != 0);
@ -789,8 +789,15 @@ class ObjectType : Type
}
override:
// getClass does all the error checking we need
void validate() { getClass(); }
void validate(Floc loc)
{
// getClass does most of the error checking we need
auto mc = getClass(loc);
// check that we're not using a module as a type
if(mc.isModule)
fail("Cannot use module " ~ name ~ " as a type", loc);
}
int getSize() { return 1; }
bool isObject() { return true; }
@ -847,8 +854,8 @@ class ObjectType : Type
// This is called when the type is defined, and it can forward
// reference classes that do not exist yet. The classes must exist
// by the time getClass() is called though, usually when class body
// (not just the header) is being resolved.
// by the time getClass() is called though, usually when the class
// body (not just the header) is being resolved.
void resolve(Scope sc)
{
clsIndex = global.getForwardIndex(name);
@ -884,7 +891,7 @@ class ArrayType : Type
}
override:
void validate() { assert(base !is null); base.validate(); }
void validate(Floc loc) { assert(base !is null); base.validate(loc); }
int arrays() { return base.arrays() + 1; }
int getSize() { return 1; }
int[] defaultInit() { return makeData!(int)(0); }
@ -975,10 +982,10 @@ class StructType : Type
override:
// Calls validate for all member types
void validate()
void validate(Floc loc)
{
foreach(v; vars)
v.type.validate();
v.type.validate(loc);
}
// Resolves member

@ -375,7 +375,7 @@ class VarDeclaration : Block
void compile()
{
// Validate the type
var.type.validate();
var.type.validate(loc);
setLine();
@ -813,7 +813,7 @@ class VarDeclStatement : Statement
void validate()
{
assert(vars.length >= 1);
vars[0].var.type.validate();
vars[0].var.type.validate(loc);
}
// Insert local variable(s) on the stack.

@ -478,7 +478,8 @@ final class MonsterClass
// Get the singleton object
MonsterObject* getSing()
{
assert(isSingleton());
if(!isSingleton)
fail("Class is not a singleton: " ~ name.str);
requireCompile();
assert(singObj !is null);
return singObj;
@ -492,6 +493,9 @@ final class MonsterClass
if(isAbstract)
fail("Cannot create objects from abstract class " ~ name.str);
if(isModule && singObj !is null)
fail("Cannot create instances of module " ~ name.str);
// Create the thread
CodeThread *trd = threads.getNew();
@ -588,6 +592,9 @@ final class MonsterClass
{
assert(obj.cls is this);
if(isModule)
fail("Cannot delete instances of module " ~ name.str);
// Get the head object
obj = obj.thread.topObj;
@ -1049,11 +1056,8 @@ final class MonsterClass
if(!isNext(tokens, TT.Identifier, name))
fail("Class statement expected identifier", tokens);
if(isModule)
{
assert(isSingleton);
fail("Modules are not implement yet.", name.loc);
}
// Module implies singleton
assert(isSingleton || !isModule);
if(isSingleton && isAbstract)
fail("Modules and singletons cannot be abstract", name.loc);

@ -24,7 +24,7 @@
// Contains all the game settings (GMST) variables of Morrowind,
// Tribunal and Bloodmoon. Based on "Morrowind Scripting for Dummies"
// (v9).
singleton GameSettings : Object;
singleton GMST : Object;
// Most of the comments are copied from MSfD. A bit of cleanup is
// still needed.
@ -2090,7 +2090,7 @@ char[] sMagicCreature05ID;
test()
{
// Print out some random variables. If you want these not to get
// lost in a see of output from OGRE, run openmw with the -n switch
// lost in a sea of output from OGRE, run openmw with the -n switch
// to disable rendering.
print();
print("Some random GMST variables:");

@ -10,11 +10,12 @@ state printMessage
{
// This state code will run as long as the object is in this state.
begin:
sleep(10);
sleep(6);
loop:
print("Howdy from the world of Monster scripts!");
print("This script is located in mscripts/test.mn. Check it out!");
print("GMST.sThief: ", GMST.sThief);
sleep(60);
goto loop;
}

@ -10,10 +10,10 @@ MonsterObject *gmstObj;
void loadGameSettings()
{
// Load the GameSettings Monster class, and create an instance.
MonsterClass mc = new MonsterClass("GameSettings");
MonsterObject *mo = mc.createObject;
gmstObj = mo;
// Load the GameSettings Monster class, and get the singleton
// instance
MonsterClass mc = MonsterClass.find("GMST");
gmstObj = mc.getSing();
foreach(a, b; gameSettings.names)
{
@ -38,13 +38,13 @@ void loadGameSettings()
continue;
}
if(b.type == VarType.Int) mo.setInt(name, b.i);
else if(b.type == VarType.Float) mo.setFloat(name, b.f);
if(b.type == VarType.Int) gmstObj.setInt(name, b.i);
else if(b.type == VarType.Float) gmstObj.setFloat(name, b.f);
// TODO: At some point we will probably translate strings into
// UTF32 at load time, so string8 will not be needed here.
else if(b.type == VarType.String) mo.setString8(name, b.str);
else if(b.type == VarType.String) gmstObj.setString8(name, b.str);
}
// Call the test function
mo.call("test");
gmstObj.call("test");
}

Loading…
Cancel
Save