This repository was archived by the owner on Nov 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleExportInterface.cs
More file actions
100 lines (91 loc) · 3.13 KB
/
ModuleExportInterface.cs
File metadata and controls
100 lines (91 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.Runtime.InteropServices;
using GMLoaded.Native;
using GMLoaded;
using GMLoaded.Lua;
using System.Text;
namespace ModuleExample
{
public static class ModuleExportInterface
{
[return: MarshalAs(UnmanagedType.I4)]
public static Int32 Close32([MarshalAs(UnmanagedType.I4)]Int32 Ptr)
{
try
{
GLua Lua = GLua.Get(Marshal.PtrToStructure<Lua_State32>(new IntPtr(Ptr)));
Int32 Ret = Module.Close(Lua);
Lua.Close();
return Ret;
}
catch (Exception E)
{
WriteException(E);
return -1;
}
}
[return: MarshalAs(UnmanagedType.I4)]
public static Int32 Close64([MarshalAs(UnmanagedType.I8)]Int64 Ptr)
{
try
{
GLua Lua = GLua.Get(Marshal.PtrToStructure<Lua_State64>(new IntPtr(Ptr)));
Int32 Ret = Module.Close(Lua);
Lua.Close();
return Ret;
}
catch (Exception E)
{
WriteException(E);
return -1;
}
}
public static void Define(
[MarshalAs(UnmanagedType.Bool)] Boolean isX64,
[MarshalAs(UnmanagedType.U1)] Byte Syscode
) => Natives.Init(isX64, (GMLoaded.System)Syscode);
[return: MarshalAs(UnmanagedType.I4)]
public static Int32 Open32([MarshalAs(UnmanagedType.I4)]Int32 Ptr)
{
try
{
return Module.Open(GLua.Get(Marshal.PtrToStructure<Lua_State32>(new IntPtr(Ptr))));
}
catch (Exception E)
{
WriteException(E);
return -1;
}
}
[return: MarshalAs(UnmanagedType.I4)]
public static Int32 Open64([MarshalAs(UnmanagedType.I8)]Int64 Ptr)
{
try
{
return Module.Open(GLua.Get(Marshal.PtrToStructure<Lua_State64>(new IntPtr(Ptr))));
}
catch (Exception E)
{
WriteException(E);
return -1;
}
}
public static void Write(String Text) => System.IO.File.AppendAllText("csModuleErrLog.Log", $"\n{DateTime.Now.ToString()}\n{Text}\n");
public static void WriteException(Exception E)
{
StringBuilder Builder = new StringBuilder($"\n{DateTime.Now.ToString()}");
String Indent = "";
void WriteE(Exception E)
{
Builder.Append($"\n{Indent}Exception:{E.Message}\n{Indent}Type:{E.GetType()}");
Indent += " ";
Builder.Append($"\n{Indent}{E.StackTrace}\n");
if (E.InnerException != null)
WriteE(E.InnerException);
Indent = Indent.Substring(1);
}
WriteE(E);
global::System.IO.File.AppendAllText("csModuleErrLog.Log", Builder.ToString());
}
}
}