protected void LoadWasm(WasmFile file, ContentsStore store = null) { if (store == null) { store = new ContentsStore(); } var importer = new PredefinedImporter(); var wasiFunctions = new List <string>() { "proc_exit", "fd_write", "fd_prestat_get", "fd_prestat_dir_name", "environ_sizes_get", "environ_get", //"env.abort", "abort", }; foreach (var wasiFunction in wasiFunctions) { importer.DefineFunction(wasiFunction, new DelegateFunctionDefinition( new WasmValueType[] { }, new WasmValueType[] { }, x => x )); } var gameObjectBinding = new GameObjectBinding(transform, store); importer.IncludeDefinitions(gameObjectBinding.Importer); var transformBinding = new TransformBinding(transform, store); importer.IncludeDefinitions(transformBinding.Importer); var physicsBinding = new PhysicsBinding(transform, store); importer.IncludeDefinitions(physicsBinding.Importer); var timeBinding = new TimeBinding(); importer.IncludeDefinitions(timeBinding.Importer); module = ModuleInstance.Instantiate(file, importer); var exportedFunctions = module.ExportedFunctions; exportedFunctions.TryGetValue("update", out updateFunction); exportedFunctions.TryGetValue("on_touch_start", out onTouchStartFunction); }
public async Task LoadWasmFromUrl(string url, ContentsStore contentsStore = null) { var httpClient = new HttpClient(); var result = await httpClient.GetAsync(url); if (result.IsSuccessStatusCode) { var stream = await result.Content.ReadAsStreamAsync(); LoadWasm(stream, contentsStore); } }
private void Awake() { contentsStore = new ContentsStore() { RootTransform = transform }; var resourceObject = new GameObject("resource"); resourceObject.SetActive(false); resourceRoot = resourceObject.transform; resourceRoot.SetParent(transform, false); LoadFromFile(path); }
protected bool TryGetElementWithArg(ArgumentParser parser, ContentsStore store, out Element element) { if (!parser.TryReadInt(out var elementIndex)) { element = null; return(false); } if (elementIndex == 0) { element = thisElement; return(true); } if (!store.TryGetElementByElementIndex(elementIndex, out element)) { return(false); } return(true); }
public PhysicsBinding(Transform transform, ContentsStore store) : base() { this.transform = transform; this.store = store; }
public void LoadWasm(Stream stream, ContentsStore store = null) { var file = WasmFile.ReadBinary(stream); LoadWasm(file, store); }
public void LoadWasm(string path, ContentsStore store = null) { var file = WasmFile.ReadBinary(path); LoadWasm(file, store); }
public TransformBinding(Element element, ContentsStore store) : base(element, store) { }
public ArgsBinding(Element element, ContentsStore store, List <string> args) : base(element, store) { this.args = args; }
public TimeBinding(Element element, ContentsStore store) : base(element, store) { }
public PhysicsBinding(Element element, ContentsStore store) : base(element, store) { }
public DebugBinding(Element element, ContentsStore store) : base(element, store) { }
public GameObjectBinding(Transform transform, ContentsStore store) : base() { this.transform = transform; this.store = store; }
public void LoadWasm(Stream stream, ContentsStore store = null, List <string> args = null) { var file = WasmFile.ReadBinary(stream); LoadWasm(file, store, args); }
public BindingBase(Element element, ContentsStore store) { Importer = GenerateImporter(); this.thisElement = element; this.store = store; }
protected void LoadWasm(WasmFile file, ContentsStore store = null, List <string> args = null) { if (store == null) { store = new ContentsStore(); } var importer = new PredefinedImporter(); var wasiFunctions = new List <string>() { "proc_exit", "fd_read", "fd_write", "fd_prestat_get", "fd_prestat_dir_name", "environ_sizes_get", "environ_get", // "random_get", //"env.abort", "abort", }; foreach (var wasiFunction in wasiFunctions) { importer.DefineFunction(wasiFunction, new DelegateFunctionDefinition( new WasmValueType[] { }, new WasmValueType[] { }, x => x )); } importer.DefineFunction("random_get", new DelegateFunctionDefinition( ValueType.PointerAndPointer, ValueType.Int, x => ReturnValue.FromObject(0) )); var element = new Element() { GameObject = gameObject }; if (args == null) { args = new List <string>(); } var scriptName = ""; args.Insert(0, scriptName); var argsBinding = new ArgsBinding(element, store, args); importer.IncludeDefinitions(argsBinding.Importer); var debugBinding = new DebugBinding(element, store); importer.IncludeDefinitions(debugBinding.Importer); var gameObjectBinding = new GameObjectBinding(element, store); importer.IncludeDefinitions(gameObjectBinding.Importer); var transformBinding = new TransformBinding(element, store); importer.IncludeDefinitions(transformBinding.Importer); var physicsBinding = new PhysicsBinding(element, store); importer.IncludeDefinitions(physicsBinding.Importer); var timeBinding = new TimeBinding(element, store); importer.IncludeDefinitions(timeBinding.Importer); module = ModuleInstance.Instantiate(file, importer); argsBinding.ModuleInstance = module; gameObjectBinding.ModuleInstance = module; debugBinding.ModuleInstance = module; var exportedFunctions = module.ExportedFunctions; exportedFunctions.TryGetValue("start", out startFunction); exportedFunctions.TryGetValue("update", out updateFunction); exportedFunctions.TryGetValue("on_touch_start", out onTouchStartFunction); exportedFunctions.TryGetValue("on_use", out onUseFunction); }
public GameObjectBinding(Element element, ContentsStore store) : base(element, store) { }