mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-06 05:01:53 +00:00
Wer weiß, was ich alles so gemacht hatte...
- Fixed crash caused by early ScriptEngine shutdown
This commit is contained in:
@@ -1,9 +1,24 @@
|
||||
using Mono;
|
||||
using System;
|
||||
using GlitchyEngine.Core;
|
||||
using System.Collections;
|
||||
|
||||
namespace GlitchyEngine.Scripting;
|
||||
|
||||
using internal GlitchyEngine.Scripting;
|
||||
|
||||
public struct ScriptField
|
||||
{
|
||||
public StringView Name;
|
||||
internal MonoClassField* _monoField;
|
||||
|
||||
internal this(StringView name, MonoClassField* monoField)
|
||||
{
|
||||
Name = name;
|
||||
_monoField = monoField;
|
||||
}
|
||||
}
|
||||
|
||||
class ScriptClass : RefCounter
|
||||
{
|
||||
private String _namespace ~ delete _;
|
||||
@@ -12,6 +27,9 @@ class ScriptClass : RefCounter
|
||||
|
||||
private MonoClass* _monoClass;
|
||||
|
||||
//private List<MonoClassField*> _monoFields ~ delete _;
|
||||
private Dictionary<StringView, ScriptField> _monoFields ~ delete _;
|
||||
|
||||
//typealias ConstructorMethod = function void(MonoObject* instance, UUID uuid, MonoException** exception);
|
||||
typealias OnCreateMethod = function MonoObject*(MonoObject* instance, MonoException** exception);
|
||||
typealias OnUpdateMethod = function MonoObject*(MonoObject* instance, float deltaTime, MonoException** exception);
|
||||
@@ -27,6 +45,8 @@ class ScriptClass : RefCounter
|
||||
public StringView ClassName => _className;
|
||||
public StringView FullName => _fullName;
|
||||
|
||||
public Dictionary<StringView, ScriptField> Fields => _monoFields;
|
||||
|
||||
[AllowAppend]
|
||||
public this(StringView classNamespace, StringView className)
|
||||
{
|
||||
@@ -41,6 +61,24 @@ class ScriptClass : RefCounter
|
||||
_onCreate = (OnCreateMethod)GetMethodThunk("OnCreate");
|
||||
_onUpdate = (OnUpdateMethod)GetMethodThunk("OnUpdate", 1);
|
||||
_onDestroy = (OnDestroyMethod)GetMethodThunk("OnDestroy");
|
||||
|
||||
ExtractFields();
|
||||
}
|
||||
|
||||
private void ExtractFields()
|
||||
{
|
||||
//_monoFields = new List<MonoClassField*>();´
|
||||
_monoFields = new Dictionary<StringView, ScriptField>();
|
||||
|
||||
void* iterator = null;
|
||||
MonoClassField* currentField = null;
|
||||
while ((currentField = Mono.mono_class_get_fields(_monoClass, &iterator)) != null)
|
||||
{
|
||||
// TODO: does the pointer from mono really never move?
|
||||
StringView name = StringView(Mono.mono_field_get_name(currentField));
|
||||
|
||||
_monoFields[name] = .(name, currentField);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnCreate(MonoObject* instance)
|
||||
|
||||
Reference in New Issue
Block a user