2010-01-09 11:20:14 -08:00
|
|
|
function TestScript1_values() {}
|
|
|
|
|
|
2025-12-30 00:57:37 -08:00
|
|
|
TestScript1_values.prototype.Init = function()
|
|
|
|
|
{
|
2010-01-09 11:20:14 -08:00
|
|
|
this.x = +this.template.x;
|
|
|
|
|
this.str = "this is a string";
|
2020-12-27 09:18:13 -08:00
|
|
|
this.things = { "a": 1, "b": "2", "c": [3, "4", [5, []]] };
|
2010-01-09 11:20:14 -08:00
|
|
|
};
|
|
|
|
|
|
2025-12-30 00:57:37 -08:00
|
|
|
TestScript1_values.prototype.GetX = function()
|
|
|
|
|
{
|
2010-01-09 11:20:14 -08:00
|
|
|
// print(uneval(this));
|
|
|
|
|
return this.x;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Engine.RegisterComponentType(IID_Test1, "TestScript1_values", TestScript1_values);
|
|
|
|
|
|
|
|
|
|
// -------- //
|
|
|
|
|
|
|
|
|
|
function TestScript1_entity() {}
|
|
|
|
|
|
2025-12-30 00:57:37 -08:00
|
|
|
TestScript1_entity.prototype.GetX = function()
|
|
|
|
|
{
|
2010-01-09 11:20:14 -08:00
|
|
|
// Test that .entity is readonly
|
2025-12-30 00:57:37 -08:00
|
|
|
try
|
|
|
|
|
{
|
2010-11-16 15:00:52 -08:00
|
|
|
delete this.entity;
|
|
|
|
|
Engine.TS_FAIL("Missed exception");
|
2025-12-30 00:57:37 -08:00
|
|
|
}
|
|
|
|
|
catch(e) { /* OK */ }
|
|
|
|
|
try
|
|
|
|
|
{
|
2010-11-16 15:00:52 -08:00
|
|
|
this.entity = -1;
|
|
|
|
|
Engine.TS_FAIL("Missed exception");
|
2025-12-30 00:57:37 -08:00
|
|
|
}
|
|
|
|
|
catch(e) { /* OK */ }
|
2010-01-09 11:20:14 -08:00
|
|
|
|
|
|
|
|
// and return the value
|
|
|
|
|
return this.entity;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Engine.RegisterComponentType(IID_Test1, "TestScript1_entity", TestScript1_entity);
|
|
|
|
|
|
|
|
|
|
// -------- //
|
|
|
|
|
|
|
|
|
|
function TestScript1_nontree() {}
|
|
|
|
|
|
2025-12-30 00:57:37 -08:00
|
|
|
TestScript1_nontree.prototype.Init = function()
|
|
|
|
|
{
|
2010-01-09 11:20:14 -08:00
|
|
|
var n = [1];
|
2020-12-27 09:18:13 -08:00
|
|
|
this.x = [n, n, null, { "y": n }];
|
2010-01-09 11:20:14 -08:00
|
|
|
this.x[2] = this.x;
|
|
|
|
|
};
|
|
|
|
|
|
2025-12-30 00:57:37 -08:00
|
|
|
TestScript1_nontree.prototype.GetX = function()
|
|
|
|
|
{
|
2010-01-09 11:20:14 -08:00
|
|
|
// print(uneval(this)+"\n");
|
|
|
|
|
this.x[0][0] += 1;
|
|
|
|
|
return this.x[0][0] + this.x[1][0] + this.x[2][0][0] + this.x[3].y[0];
|
2019-07-01 04:09:19 -07:00
|
|
|
};
|
2010-01-09 11:20:14 -08:00
|
|
|
|
|
|
|
|
Engine.RegisterComponentType(IID_Test1, "TestScript1_nontree", TestScript1_nontree);
|
|
|
|
|
|
|
|
|
|
// -------- //
|
|
|
|
|
|
2010-05-22 16:02:07 -07:00
|
|
|
function TestScript1_custom() {}
|
|
|
|
|
|
2025-12-30 00:57:37 -08:00
|
|
|
TestScript1_custom.prototype.Init = function()
|
|
|
|
|
{
|
2010-05-22 16:02:07 -07:00
|
|
|
this.y = 2;
|
|
|
|
|
};
|
|
|
|
|
|
2025-12-30 00:57:37 -08:00
|
|
|
TestScript1_custom.prototype.Serialize = function()
|
|
|
|
|
{
|
2020-12-27 09:18:13 -08:00
|
|
|
return { "c": 1 };
|
|
|
|
|
};
|
|
|
|
|
|
2025-12-30 00:57:37 -08:00
|
|
|
TestScript1_custom.prototype.Deserialize = function(data)
|
|
|
|
|
{
|
2020-12-27 09:18:13 -08:00
|
|
|
this.c = data.c;
|
2010-05-22 16:02:07 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Engine.RegisterComponentType(IID_Test1, "TestScript1_custom", TestScript1_custom);
|
|
|
|
|
|
|
|
|
|
// -------- //
|
|
|
|
|
|
2010-01-09 11:20:14 -08:00
|
|
|
function TestScript1_getter() {}
|
|
|
|
|
|
2025-12-30 00:57:37 -08:00
|
|
|
TestScript1_getter.prototype.Init = function()
|
|
|
|
|
{
|
2010-01-09 11:20:14 -08:00
|
|
|
this.x = 100;
|
2020-12-27 09:18:13 -08:00
|
|
|
this.__defineGetter__('x', function() { print("FAIL\n"); die(); return 200; });
|
2010-01-09 11:20:14 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Engine.RegisterComponentType(IID_Test1, "TestScript1_getter", TestScript1_getter);
|
|
|
|
|
|
|
|
|
|
// -------- //
|
|
|
|
|
|
|
|
|
|
function TestScript1_consts() {}
|
|
|
|
|
|
2010-04-14 10:22:32 -07:00
|
|
|
TestScript1_consts.prototype.Schema = "<ref name='anything'/>";
|
|
|
|
|
|
2025-12-30 00:57:37 -08:00
|
|
|
TestScript1_consts.prototype.Init = function()
|
|
|
|
|
{
|
2021-01-12 08:15:40 -08:00
|
|
|
this.cached = (+this.entity) + (+this.template.x);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TestScript1_consts.prototype.Serialize = null;
|
|
|
|
|
|
2025-12-30 00:57:37 -08:00
|
|
|
TestScript1_consts.prototype.Deserialize = function(data)
|
|
|
|
|
{
|
2021-01-12 08:15:40 -08:00
|
|
|
this.Init();
|
|
|
|
|
};
|
|
|
|
|
|
2025-12-30 00:57:37 -08:00
|
|
|
TestScript1_consts.prototype.GetX = function()
|
|
|
|
|
{
|
2021-01-12 08:15:40 -08:00
|
|
|
return this.cached;
|
2010-01-09 11:20:14 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Engine.RegisterComponentType(IID_Test1, "TestScript1_consts", TestScript1_consts);
|