Jint 2.2 vs Jint 0.9+Magma

mikec

Master Of All That I Survey
Retired Staff
Trusted Member
Jul 12, 2014
296
152
28
Los Angeles, California, USA
Fougerite + Jint 2.2
Magma + Jint 0.9
Arrays always have .length property, never .Length
Only Javascript arrays have .length, C# arrays have .Length
C# method .ToString() works only if C# object has that method
.ToString() and .toString() are faked for any object
Javascript method .toString() works on Javascript objects that have the method
.toString() and .ToString() are faked for any object
Type conversion to string in a string context works like it should in Javascript, without calling .ToString()
Type conversion is hit or miss, with many workarounds existing
Comparisons of values to null behave correctly, whether C# null or Javascript null
Comparisions of values to C# null sometimes work and sometimes do not
Javascript typeof identifies C# objects with the corresponding Javascript types. string=string, function=function, number=number, and so on.
Javascript typeof always reports "object" for any C# object of any kind.
Only nullable C# types can ever == null. "obj != null" is always true for most objects referenced by plugins. It is rarely necessary to check "if(obj != null)".
Any C# type, property, or method could have a null value, whether or not it could have a null value in C#
The loop expression "for(var x in obj)" does not enumerate properties of C# objects except for arrays and one-dimensional lists. Var "x" refers to the index of the property, and the property is accessed as "obj[x]".
The loop expression "for(var i in obj)" enumerates properties of C# objects in the same way as the C# foreach loop, and the property reference is returned to "i", not the index.
Y0u can call the enumerator for C# classes, such as a Dictionary, instead of the "for...in" loop.
You can do what with what?
You can call any generic class by passing the type.
You could call some generic classes by using the non-standard notation {type} to pass the type.
The new operator works, and can instantiate C# classes or Javascript objects. Fougerite does not edit plugin scripts, except to add Magma compatibility to the global namespace.
The new operator is edited out of scripts by Magma as they are loaded, and replaced with a call to one of Magma's Util.GetInstance methods. It often called the wrong GetInstance method. The only plugin I know of where this works is Drop++.
Namespaces other than System are imported into Javascript with a global Javascript method.
Classes in all namespaces can be referenced with the full path.
Access for Javascript to C# types is given by loading the Assembly with that type into the Engine at runtime.
All C# types in any Assembly in the execution context can be accessed from Javascript.
Assigning a value to a identifier that has not been declared with var attaches that identifier to the Global object, like it does in real Javascript.
Any reference to an undeclared identifier throws an exception.
"Primitive" types - string, integer, boolean - passed to your hooks are Javascript primitives with Javascript properties and methods. That includes arrays.
"Primitive" types passed from C# are C# value types, with C# properties and methods.
 
Last edited:
  • Informative
Reactions: Ramm

mikec

Master Of All That I Survey
Retired Staff
Trusted Member
Jul 12, 2014
296
152
28
Los Angeles, California, USA
It's mostly better, but enumerating properties of game objects to discover what you can do with them isn't as easy in Jint2.

The loop expression "for(var x in obj)" does not enumerate properties of C# objects except for arrays and one-dimensional lists. Var "x" refers to the index of the element, and the element is accessed as "obj[x]".
In the case of a Dictionary, "obj[x]" returns the KeyValuePair object to Javascript, not the Value like it would in Jint 0.9. So to get the Value, you have to refer to "obj[x].Value" in Jint2. You can get the Key with obj[x].Key.

But this is the right way to do it, in my view. Javascript doesn't have a foreach loop.
 

mikec

Master Of All That I Survey
Retired Staff
Trusted Member
Jul 12, 2014
296
152
28
Los Angeles, California, USA
Since it's awkward to deal with Dictionaries and some other C# collections in Javascript under Jint2, I'm writing a new class for the JintPlugin that will make it much easier for scripts to manipulate collections of game objects. These are exclusive to Jint2, for now. Here's a sample of some of the methods and properties that will be available in a build I will upload very soon. I have a lot of documenting to do. :cool:

Code:
/* JintPlugin Lookup API
Lookup.Structures.All:StructureMaster[]
Lookup.Structures.LargerThan(StructureMaster structure):StructureMaster[]
Lookup.Structures.LargerThan(Vector3 size):StructureMaster[]
... and other overloads, and SmallerThan, EqualTo methods
Lookup.Structures.Census:Dictionary<string, int>  (key=ownerID, val=count)
Lookup.Structures.OneRoom:Structuremaster[]
Lookup.Sleepers.All:SleepingAvatar[]
Lookup.Sleepers.Owners:string[]
Lookup.Storage.All:SaveableInventory[]
Lookup.Fires.All:FireBarrel[]
... and many more subclasses like this with common properties All, Census, Owners

various Enums for use in Filter() method overloads
Lookup.Material.Metal
Lookup.Material.Wood
Lookup.Fire.Furnace
Lookup.Fire.Campfire
Lookup.Store.WoodBox
Lookup.Store.LargeWoodBox
Lookup.Store.SmallStash
Lookup.Store.Furnace
Lookup.Store.Campfire
Lookup.Store.RepairBench
Lookup.Respawn.Bed
Lookup.Respawn.Bag

...and finally, the Filter overloads. 
Lookup.Filter(StructureMaster[] structures, string ownerid):StructureMaster[]
Lookup.Filter(StructureMaster[] structures, string[] ownerIDs):StructureMaster[]
Lookup.Filter(StructureMaster[] structures, Lookup.Material material):StructureMaster[]
Lookup.Filter(StructureMaster[] structures, Vector3 location, float distance):StructureMaster[] (structures <= distance from location)
Lookup.Filter(FireBarrel[] fires, Lookup.Fire kind):FireBarrel[]
Lookup.Filter(FireBarrel[] fires, bool ontheground):FireBarrel[] (true=deployed on the ground, false=deployed on structure part)
Lookup.Filter(DeployedRespawns[] bedsnbags, Lookup.Respawn kind):DeployedRespawn[]

... bonus method
Lookup.CensusToJson(Dictionary<string, int> census):string
*/
Lookups for inventory contents are coming, too.