Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
IoTSharp
IoTSharp
提交
58944366
IoTSharp
项目概览
IoTSharp
/
IoTSharp
12 个月 前同步成功
通知
15
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
IoTSharp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
58944366
编写于
10月 07, 2021
作者:
麦壳饼
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更换lua脚本解释器继续尝试。
删除多余的项目》
上级
0727a502
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
10 addition
and
73 deletion
+10
-73
IoTSharp.Interpreter.JavaScript/IoTSharp.Interpreter.JavaScript.csproj
...rpreter.JavaScript/IoTSharp.Interpreter.JavaScript.csproj
+0
-11
IoTSharp.Interpreter.JavaScript/JavaScriptEngine.cs
IoTSharp.Interpreter.JavaScript/JavaScriptEngine.cs
+0
-50
IoTSharp.Interpreter/IoTSharp.Interpreter.csproj
IoTSharp.Interpreter/IoTSharp.Interpreter.csproj
+1
-1
IoTSharp.Interpreter/JavaScriptEngine.cs
IoTSharp.Interpreter/JavaScriptEngine.cs
+1
-1
IoTSharp.Interpreter/LuaScriptEngine.cs
IoTSharp.Interpreter/LuaScriptEngine.cs
+8
-9
IoTSharp.Test/ScriptEngineTest.cs
IoTSharp.Test/ScriptEngineTest.cs
+0
-1
未找到文件。
IoTSharp.Interpreter.JavaScript/IoTSharp.Interpreter.JavaScript.csproj
已删除
100644 → 0
浏览文件 @
0727a502
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Jint" Version="3.0.0-beta-2035" />
</ItemGroup>
</Project>
IoTSharp.Interpreter.JavaScript/JavaScriptEngine.cs
已删除
100644 → 0
浏览文件 @
0727a502
using
Jint
;
using
Jint.Native
;
using
Jint.Native.Json
;
using
Microsoft.Extensions.Logging
;
using
System
;
using
System.Threading
;
using
IoTSharp.Interpreter
;
namespace
IoTSharp.Interpreter.JavaScript
{
public
class
JavaScriptEngine
{
private
readonly
CancellationToken
_cancellationToken
;
private
readonly
Engine
_engine
;
private
readonly
JsonParser
_parser
;
private
readonly
ILogger
_logger
;
private
readonly
JsonSerializer
_serializer
;
private
string
_source
;
public
JavaScriptEngine
(
ILogger
<
JavaScriptEngine
>
logger
,
EngineSetting
setting
,
CancellationToken
cancellationToken
)
{
_cancellationToken
=
cancellationToken
;
var
engine
=
new
Engine
(
options
=>
{
// Limit memory allocations to MB
options
.
LimitMemory
(
4
_000_000
);
// Set a timeout to 4 seconds.
options
.
TimeoutInterval
(
TimeSpan
.
FromSeconds
(
setting
.
Timeout
));
// Set limit of 1000 executed statements.
// options.MaxStatements(1000);
// Use a cancellation token.
options
.
CancellationToken
(
_cancellationToken
);
});
_engine
=
engine
;
_parser
=
new
JsonParser
(
_engine
);
_logger
=
logger
;
}
public
string
Do
(
string
_source
,
string
input
)
{
var
js
=
_engine
.
SetValue
(
"input"
,
_parser
.
Parse
(
input
)).
Evaluate
(
_source
).
ToObject
();
var
json
=
System
.
Text
.
Json
.
JsonSerializer
.
Serialize
(
js
);
_logger
.
LogDebug
(
$"source:
{
Environment
.
NewLine
}{
_source
}{
Environment
.
NewLine
}{
Environment
.
NewLine
}
input:
{
Environment
.
NewLine
}{
input
}{
Environment
.
NewLine
}{
Environment
.
NewLine
}
ouput:
{
Environment
.
NewLine
}{
json
}{
Environment
.
NewLine
}{
Environment
.
NewLine
}
"
);
return
json
;
}
}
}
IoTSharp.Interpreter/IoTSharp.Interpreter.csproj
浏览文件 @
58944366
...
...
@@ -7,7 +7,7 @@
<PackageReference Include="Jint" Version="3.0.0-beta-2035" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
<PackageReference Include="IronPython" Version="3.4.0-alpha1" />
<PackageReference Include="
MoonSharp" Version="2.0.0
" />
<PackageReference Include="
NeoLua" Version="1.3.13
" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
...
...
IoTSharp.Interpreter/JavaScriptEngine.cs
浏览文件 @
58944366
...
...
@@ -7,7 +7,7 @@ using System.Threading;
using
IoTSharp.Interpreter
;
using
Esprima
;
namespace
IoTSharp.Interpreter
.JavaScript
namespace
IoTSharp.Interpreter
{
public
class
JavaScriptEngine
:
ScriptEngineBase
{
...
...
IoTSharp.Interpreter/LuaScriptEngine.cs
浏览文件 @
58944366
using
Microsoft.Extensions.Logging
;
using
Microsoft.Scripting.Hosting
;
using
MoonSharp.Interpreter
;
using
Neo.IronLua
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Converters
;
using
System
;
...
...
@@ -11,22 +11,21 @@ namespace IoTSharp.Interpreter
{
public
class
LuaScriptEngine
:
ScriptEngineBase
{
private
Script
_engine
;
private
Lua
_engine
;
private
LuaGlobal
env
;
public
LuaScriptEngine
(
ILogger
<
LuaScriptEngine
>
logger
,
EngineSetting
setting
,
CancellationToken
cancellationToken
)
:
base
(
logger
,
setting
,
cancellationToken
)
{
_engine
=
new
Script
();
_engine
=
new
Lua
();
env
=
_engine
.
CreateEnvironment
();
// Create a environment
}
public
override
string
Do
(
string
_source
,
string
input
)
{
var
expConverter
=
new
ExpandoObjectConverter
();
dynamic
obj
=
JsonConvert
.
DeserializeObject
<
ExpandoObject
>(
input
,
expConverter
);
UserData
.
RegisterExtensionType
(
obj
.
GetType
());
UserData
.
RegisterType
(
obj
.
GetType
());
DynValue
dvobj
=
UserData
.
Create
(
obj
);
_engine
.
Globals
.
Set
(
"input"
,
dvobj
);
DynValue
res
=
_engine
.
DoString
(
_source
);
var
outputjson
=
res
.
ToObject
().
ToString
();
env
[
"input"
]
=
obj
;
var
res
=
env
.
DoChunk
(
_source
,
"lua_iotsharp"
);
var
outputjson
=
res
.
ToString
();
return
outputjson
;
}
}
...
...
IoTSharp.Test/ScriptEngineTest.cs
浏览文件 @
58944366
using
IoTSharp.Interpreter
;
using
IoTSharp.Interpreter.JavaScript
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
System
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录