Closed MeikelLP closed 5 years ago
What version of Jint? Running such script with latest preview version doesn't give an error even though registry
is not defined.
I'm not at work right now so I can't say for sure. I directly downloaded from nuget today. Should be 3.0.0-beta-1525
. I'm adding more source code (especially C#) tomorrow.
I used nuget download Jint as dependecy @ 3.0.0-beta-1525
. While stripping down my code I ran into another issue. I reply once I got a minimal example.
Somehow I'm now stuck with Unhandled Exception: System.InvalidCastException: Object must implement IConvertible
. I can see why this happens (can't convert ExpandoObject
to ModuleExports
but is this by design? Can't I assign a "anonymous" Javascript object to my typed field/property?
I can make it work with explicitly defining the ModuleExports
type but this completely kills the purpose of JS here (IMO).
var exports = new ModuleExports()
exports.name = 'Mod1'
exports.init = function () {
registry.Add(new BlockPrototype('Dirt', 'assets/dirt.png'))
registry.Add(new BlockPrototype('Grass', 'assets/grass.png'))
}
module.exports = exports
and
engine.SetValue(nameof(ModuleExports), TypeReference.CreateTypeReference(engine, typeof(ModuleExports)));
I cannot reproduce this bug anymore. I don't know how it fixed itself :/
I want to implement a (for now) basic modding interface for my Unity3D game.
I want to define a mod in
module.exports
styled manner:And then call the individual phase while mod-loading (i.e.
init
). But sadly the functioninit
is instantly called when IEngine.Execute
this script block. This should not happen as I only define this function.I tried to workaround this issue with defining the function separately as named
function init () {}
and then assign it but that didn't work as well.