mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 22:23:51 +00:00
More scripting updates
git-svn-id: https://openmw.svn.sourceforge.net/svnroot/openmw/trunk@78 ea6a568a-9f4f-0410-981a-c910a81bb256
This commit is contained in:
parent
0d7b08cbae
commit
838d4f0ebe
8 changed files with 49 additions and 31 deletions
|
@ -518,7 +518,13 @@ class NewExpression : Expression
|
||||||
{
|
{
|
||||||
// We need to find the index associated with this class, and
|
// We need to find the index associated with this class, and
|
||||||
// pass it to the assembler.
|
// 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)
|
else if(type.isArray)
|
||||||
{
|
{
|
||||||
|
|
|
@ -635,9 +635,9 @@ class FuncDeclaration : Statement
|
||||||
{
|
{
|
||||||
// Validate all types (make sure there are no dangling forward
|
// Validate all types (make sure there are no dangling forward
|
||||||
// references)
|
// references)
|
||||||
fn.type.validate();
|
fn.type.validate(fn.name.loc);
|
||||||
foreach(p; fn.params)
|
foreach(p; fn.params)
|
||||||
p.type.validate();
|
p.type.validate(fn.name.loc);
|
||||||
|
|
||||||
if(code !is null)
|
if(code !is null)
|
||||||
code.resolve(sc);
|
code.resolve(sc);
|
||||||
|
|
|
@ -231,7 +231,7 @@ abstract class Type : Block
|
||||||
|
|
||||||
// Validate that this type actually exists. This is used to make
|
// Validate that this type actually exists. This is used to make
|
||||||
// sure that all forward references are resolved.
|
// sure that all forward references are resolved.
|
||||||
void validate() {}
|
void validate(Floc loc) {}
|
||||||
|
|
||||||
// Check if this type is equivalent to the given D type
|
// Check if this type is equivalent to the given D type
|
||||||
final bool isDType(TypeInfo ti)
|
final bool isDType(TypeInfo ti)
|
||||||
|
@ -777,7 +777,7 @@ class ObjectType : Type
|
||||||
clsIndex = mc.gIndex;
|
clsIndex = mc.gIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
MonsterClass getClass()
|
MonsterClass getClass(Floc loc = Floc.init)
|
||||||
{
|
{
|
||||||
assert(clsIndex != 0);
|
assert(clsIndex != 0);
|
||||||
|
|
||||||
|
@ -789,8 +789,15 @@ class ObjectType : Type
|
||||||
}
|
}
|
||||||
|
|
||||||
override:
|
override:
|
||||||
// getClass does all the error checking we need
|
void validate(Floc loc)
|
||||||
void validate() { getClass(); }
|
{
|
||||||
|
// 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; }
|
int getSize() { return 1; }
|
||||||
bool isObject() { return true; }
|
bool isObject() { return true; }
|
||||||
|
@ -847,8 +854,8 @@ class ObjectType : Type
|
||||||
|
|
||||||
// This is called when the type is defined, and it can forward
|
// This is called when the type is defined, and it can forward
|
||||||
// reference classes that do not exist yet. The classes must exist
|
// reference classes that do not exist yet. The classes must exist
|
||||||
// by the time getClass() is called though, usually when class body
|
// by the time getClass() is called though, usually when the class
|
||||||
// (not just the header) is being resolved.
|
// body (not just the header) is being resolved.
|
||||||
void resolve(Scope sc)
|
void resolve(Scope sc)
|
||||||
{
|
{
|
||||||
clsIndex = global.getForwardIndex(name);
|
clsIndex = global.getForwardIndex(name);
|
||||||
|
@ -884,7 +891,7 @@ class ArrayType : Type
|
||||||
}
|
}
|
||||||
|
|
||||||
override:
|
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 arrays() { return base.arrays() + 1; }
|
||||||
int getSize() { return 1; }
|
int getSize() { return 1; }
|
||||||
int[] defaultInit() { return makeData!(int)(0); }
|
int[] defaultInit() { return makeData!(int)(0); }
|
||||||
|
@ -975,10 +982,10 @@ class StructType : Type
|
||||||
|
|
||||||
override:
|
override:
|
||||||
// Calls validate for all member types
|
// Calls validate for all member types
|
||||||
void validate()
|
void validate(Floc loc)
|
||||||
{
|
{
|
||||||
foreach(v; vars)
|
foreach(v; vars)
|
||||||
v.type.validate();
|
v.type.validate(loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resolves member
|
// Resolves member
|
||||||
|
|
|
@ -375,7 +375,7 @@ class VarDeclaration : Block
|
||||||
void compile()
|
void compile()
|
||||||
{
|
{
|
||||||
// Validate the type
|
// Validate the type
|
||||||
var.type.validate();
|
var.type.validate(loc);
|
||||||
|
|
||||||
setLine();
|
setLine();
|
||||||
|
|
||||||
|
@ -813,7 +813,7 @@ class VarDeclStatement : Statement
|
||||||
void validate()
|
void validate()
|
||||||
{
|
{
|
||||||
assert(vars.length >= 1);
|
assert(vars.length >= 1);
|
||||||
vars[0].var.type.validate();
|
vars[0].var.type.validate(loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert local variable(s) on the stack.
|
// Insert local variable(s) on the stack.
|
||||||
|
|
|
@ -478,7 +478,8 @@ final class MonsterClass
|
||||||
// Get the singleton object
|
// Get the singleton object
|
||||||
MonsterObject* getSing()
|
MonsterObject* getSing()
|
||||||
{
|
{
|
||||||
assert(isSingleton());
|
if(!isSingleton)
|
||||||
|
fail("Class is not a singleton: " ~ name.str);
|
||||||
requireCompile();
|
requireCompile();
|
||||||
assert(singObj !is null);
|
assert(singObj !is null);
|
||||||
return singObj;
|
return singObj;
|
||||||
|
@ -492,6 +493,9 @@ final class MonsterClass
|
||||||
if(isAbstract)
|
if(isAbstract)
|
||||||
fail("Cannot create objects from abstract class " ~ name.str);
|
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
|
// Create the thread
|
||||||
CodeThread *trd = threads.getNew();
|
CodeThread *trd = threads.getNew();
|
||||||
|
|
||||||
|
@ -588,6 +592,9 @@ final class MonsterClass
|
||||||
{
|
{
|
||||||
assert(obj.cls is this);
|
assert(obj.cls is this);
|
||||||
|
|
||||||
|
if(isModule)
|
||||||
|
fail("Cannot delete instances of module " ~ name.str);
|
||||||
|
|
||||||
// Get the head object
|
// Get the head object
|
||||||
obj = obj.thread.topObj;
|
obj = obj.thread.topObj;
|
||||||
|
|
||||||
|
@ -1049,11 +1056,8 @@ final class MonsterClass
|
||||||
if(!isNext(tokens, TT.Identifier, name))
|
if(!isNext(tokens, TT.Identifier, name))
|
||||||
fail("Class statement expected identifier", tokens);
|
fail("Class statement expected identifier", tokens);
|
||||||
|
|
||||||
if(isModule)
|
// Module implies singleton
|
||||||
{
|
assert(isSingleton || !isModule);
|
||||||
assert(isSingleton);
|
|
||||||
fail("Modules are not implement yet.", name.loc);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isSingleton && isAbstract)
|
if(isSingleton && isAbstract)
|
||||||
fail("Modules and singletons cannot be abstract", name.loc);
|
fail("Modules and singletons cannot be abstract", name.loc);
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
// Contains all the game settings (GMST) variables of Morrowind,
|
// Contains all the game settings (GMST) variables of Morrowind,
|
||||||
// Tribunal and Bloodmoon. Based on "Morrowind Scripting for Dummies"
|
// Tribunal and Bloodmoon. Based on "Morrowind Scripting for Dummies"
|
||||||
// (v9).
|
// (v9).
|
||||||
singleton GameSettings : Object;
|
singleton GMST : Object;
|
||||||
|
|
||||||
// Most of the comments are copied from MSfD. A bit of cleanup is
|
// Most of the comments are copied from MSfD. A bit of cleanup is
|
||||||
// still needed.
|
// still needed.
|
||||||
|
@ -2090,7 +2090,7 @@ char[] sMagicCreature05ID;
|
||||||
test()
|
test()
|
||||||
{
|
{
|
||||||
// Print out some random variables. If you want these not to get
|
// 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.
|
// to disable rendering.
|
||||||
print();
|
print();
|
||||||
print("Some random GMST variables:");
|
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.
|
// This state code will run as long as the object is in this state.
|
||||||
begin:
|
begin:
|
||||||
sleep(10);
|
sleep(6);
|
||||||
|
|
||||||
loop:
|
loop:
|
||||||
print("Howdy from the world of Monster scripts!");
|
print("Howdy from the world of Monster scripts!");
|
||||||
print("This script is located in mscripts/test.mn. Check it out!");
|
print("This script is located in mscripts/test.mn. Check it out!");
|
||||||
|
print("GMST.sThief: ", GMST.sThief);
|
||||||
sleep(60);
|
sleep(60);
|
||||||
goto loop;
|
goto loop;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,10 @@ MonsterObject *gmstObj;
|
||||||
|
|
||||||
void loadGameSettings()
|
void loadGameSettings()
|
||||||
{
|
{
|
||||||
// Load the GameSettings Monster class, and create an instance.
|
// Load the GameSettings Monster class, and get the singleton
|
||||||
MonsterClass mc = new MonsterClass("GameSettings");
|
// instance
|
||||||
MonsterObject *mo = mc.createObject;
|
MonsterClass mc = MonsterClass.find("GMST");
|
||||||
gmstObj = mo;
|
gmstObj = mc.getSing();
|
||||||
|
|
||||||
foreach(a, b; gameSettings.names)
|
foreach(a, b; gameSettings.names)
|
||||||
{
|
{
|
||||||
|
@ -38,13 +38,13 @@ void loadGameSettings()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(b.type == VarType.Int) mo.setInt(name, b.i);
|
if(b.type == VarType.Int) gmstObj.setInt(name, b.i);
|
||||||
else if(b.type == VarType.Float) mo.setFloat(name, b.f);
|
else if(b.type == VarType.Float) gmstObj.setFloat(name, b.f);
|
||||||
// TODO: At some point we will probably translate strings into
|
// TODO: At some point we will probably translate strings into
|
||||||
// UTF32 at load time, so string8 will not be needed here.
|
// 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
|
// Call the test function
|
||||||
mo.call("test");
|
gmstObj.call("test");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue