-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
89 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Hosihikari.VanillaScript.QuickJS; | ||
using Hosihikari.VanillaScript.QuickJS.Types; | ||
|
||
namespace Hosihikari.VanillaScript.Loader; | ||
|
||
internal static partial class Manager | ||
{ | ||
internal static unsafe void LoadAllScripts(JsContext* ctx) | ||
{ | ||
var pluginsDir = Path.GetFullPath("plugins"); | ||
foreach ( | ||
var js in Directory.EnumerateFiles(pluginsDir, "*.js", SearchOption.AllDirectories) | ||
) | ||
{ | ||
try | ||
{ | ||
var bytes = File.ReadAllText(js); | ||
_ = Native.JS_Eval(ctx, js, bytes); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Logger.Error(nameof(LoadAllScripts), ex); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Hosihikari.VanillaScript.QuickJS.Extensions; | ||
using Hosihikari.VanillaScript.QuickJS.Types; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Hosihikari.VanillaScript.Loader.Modules; | ||
|
||
internal static unsafe class TestModule | ||
{ | ||
public static void Bind(JsContext* ctx, JsValue instance) | ||
{ | ||
instance.DefineFunction(ctx, "test", &test, 1); | ||
} | ||
|
||
[UnmanagedCallersOnly] | ||
private static unsafe JsValue test(JsContext* ctx, JsValue val, int argCount, JsValue* argvIn) | ||
{ | ||
var argv = new ReadOnlySpan<JsValue>(argvIn, argCount); | ||
var arg = argv[0]; | ||
Log.Logger.Debug("测试", arg.ToString(ctx)); | ||
return JsValueCreateExtension.True; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters