Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
170 commits
Select commit Hold shift + click to select a range
2f20b18
Add API to distinguish between Integer and Floating
yqs112358 Jun 15, 2021
ad30dfe
Fix Lua's isArray and getKind
yqs112358 Jul 20, 2021
f26fce3
Fix a bug about stack
yqs112358 Jul 20, 2021
0c944c5
Fix bugs
yqs112358 Jul 20, 2021
1d6035e
add python backend
LanderlYoung May 1, 2021
eebd4c2
include
LanderlYoung May 1, 2021
62ddd0b
wip
LanderlYoung Sep 21, 2021
c6463a8
update
LanderlYoung Dec 12, 2021
d261af0
x
LanderlYoung Dec 18, 2021
b5470e9
py local ref-count
LanderlYoung Dec 18, 2021
0a8edaa
py scope
LanderlYoung Dec 18, 2021
7ca2557
py equals
LanderlYoung Dec 19, 2021
e3fe67f
py arguments & newFunction
LanderlYoung Dec 19, 2021
d5a89cc
wip
LanderlYoung Dec 19, 2021
9c4a496
Merge pull request #1 from yqs112358/feature/bugfix-of-lua-array
yqs112358 Jul 31, 2022
00511b1
Fix old wrong code from PR
yqs112358 Jul 31, 2022
607adfd
Fix lua crash
yqs112358 Jul 31, 2022
d843347
Merge branch 'Tencent:main' into python
Aug 1, 2022
16758f5
add eval and many basic things
Aug 1, 2022
88412db
新增类注册,函数注册,类函数注册
Aug 2, 2022
3512265
新增prop和static
Aug 3, 2022
a230276
修复eval
Aug 3, 2022
4c3a817
fix Global and Weak
Aug 4, 2022
a65d835
Fork TestLibs from Tencent
yqs112358 Aug 4, 2022
6124393
change devops unit test to python backend
yqs112358 Aug 4, 2022
8def40d
add getScriptEngine
yqs112358 Aug 4, 2022
97b06d2
fix
Aug 4, 2022
0026359
fix Native
Aug 4, 2022
a4e9163
Small fix about Global ref
yqs112358 Aug 5, 2022
289595f
add Exception Translate
Aug 5, 2022
3cbbfd3
Fix for unittest devops
yqs112358 Aug 5, 2022
0571bba
Update unit_tests.yml
yqs112358 Aug 5, 2022
8fe38f2
add loadFile to engine (first step)
yqs112358 Aug 5, 2022
79dc32f
Merge branch 'Add-LoadFile' into python
yqs112358 Aug 5, 2022
5f633a7
Add loadFile for python backend
yqs112358 Aug 5, 2022
21d26fe
Polish PyEngine
Aug 6, 2022
ba0c42a
tmp
Aug 6, 2022
ab369d0
Try to fix python GIL scope
yqs112358 Aug 7, 2022
3312681
Fix GIL problem
yqs112358 Aug 7, 2022
85b2ad7
tmp
Aug 7, 2022
7ec4332
Fix exception deadlock
yqs112358 Aug 7, 2022
c1ceb65
Fix Scope for multi-instance GIL dead-lock
yqs112358 Aug 8, 2022
06c4836
Fix comment
yqs112358 Aug 8, 2022
024c2cc
modified: backend/Python/PyEngine.cc
Aug 8, 2022
0cbc9c4
Remove pybind11
Aug 8, 2022
f408b16
Add Class register and construct
Aug 8, 2022
a72e24a
Revert "modified: backend/Python/PyEngine.cc"
yqs112358 Aug 9, 2022
d23cc07
tmp
Aug 9, 2022
6958a48
Function warpper
Aug 9, 2022
03d2437
Fix a bug
Aug 9, 2022
35e4d53
Fix getGlobalDict crash
yqs112358 Aug 9, 2022
5be0aeb
warpFunction新增参数
Aug 10, 2022
a992b73
fix static function register & other small problems
yqs112358 Aug 22, 2022
0b1a8ed
All is fileinput
Aug 22, 2022
dde9bff
Merge branch 'python-try-to-remove-bind11' of https://github.com/Lite…
Aug 22, 2022
26e2593
debug version
Aug 22, 2022
91650c9
fix ref count
Aug 22, 2022
f1651e0
picture a cake
Aug 22, 2022
df3b5a3
picture a cake 2
Aug 23, 2022
1f925a3
fix problem of getGlobalDict
yqs112358 Aug 23, 2022
891c2cf
Fix a reference count problem
yqs112358 Aug 23, 2022
4fbd57c
picture a cake 3
Aug 23, 2022
d8f10ef
cake finishied!!!!!!!!!!
Aug 23, 2022
9eea0b1
Merge branch 'python-try-to-remove-bind11' into python
yqs112358 Aug 23, 2022
916be0c
fix static property
Aug 23, 2022
813a8f2
Finish exception system of python backend
yqs112358 Aug 24, 2022
ed12abf
Fix a global reference bug
yqs112358 Aug 24, 2022
dc61d15
Fix a memory leak
Aug 24, 2022
13d7906
better format of traceback
yqs112358 Aug 24, 2022
fa7f66e
Add two impl
Aug 24, 2022
8f6b5af
Polish code
Aug 24, 2022
f591ce2
New py_interop
Aug 24, 2022
86ad84d
New py_interop
Aug 24, 2022
80502df
Fix Weak
Aug 24, 2022
338f4ca
Fix memory leak
Aug 24, 2022
451a83a
Fix alllllllllllllllllll memory leak!!!!
Aug 24, 2022
1e9021a
tmp
Aug 24, 2022
a182f9b
Add namespace support
Aug 24, 2022
bb62c86
Fix isInstanceOf
Aug 24, 2022
ffc1815
pass basic multi-thread test & more work need to do
yqs112358 Aug 24, 2022
14df895
change oldThreadStateStack_ to TLS
yqs112358 Aug 25, 2022
3c04c0f
Fix GIL & thread state in multi-thread env thoroughly
yqs112358 Aug 25, 2022
3555cc4
Fix comment
yqs112358 Aug 25, 2022
6616800
avoid exit not-my-managed engine
yqs112358 Aug 25, 2022
46b98e4
Add module
Aug 25, 2022
25a8970
Fix destroy engine
yqs112358 Aug 25, 2022
3e3c682
Merge branch 'fix-for-unit-test' of https://github.com/LiteLDev/Scrip…
yqs112358 Aug 25, 2022
b144a5c
Fix GIL & thread state in PyEngine creation
yqs112358 Aug 25, 2022
94e544d
disable Py_EndInterpreter temporarily to fix it later
yqs112358 Aug 25, 2022
4b3002d
Fix Global Local Weak
Aug 25, 2022
affbbfc
Fix Local<Value> constructor
Aug 25, 2022
449b57b
Add code modification for python
Aug 29, 2022
a68c915
Fix exception crash bug
yqs112358 Aug 29, 2022
391e09f
Fix eval expression check (temp fix)
yqs112358 Aug 29, 2022
af79350
Fix an string error
Aug 29, 2022
df7164b
Merge branch 'fix-for-unit-test' of https://github.com/LiteLDev/Scrip…
Aug 29, 2022
412343d
add document for python
yqs112358 Aug 29, 2022
a26ca8b
Fix Array::set
Aug 29, 2022
a43e2a1
Merge branch 'fix-for-unit-test' of https://github.com/LiteLDev/Scrip…
Aug 29, 2022
4a176d2
Fix isByteBuffer
Aug 29, 2022
7dc7049
Fix type judgement
Aug 29, 2022
eb23dea
Fix unsupported
Aug 29, 2022
58be8b6
Polish the namespace support
Aug 30, 2022
246c577
Fix namespace waining
Aug 30, 2022
3f460a8
Modify class register
Aug 31, 2022
de7c2b0
Uncompeleted code
Sep 1, 2022
5cfcb76
Python warp
Sep 2, 2022
51ceecf
Merge pull request #3 from LiteLDev/fix-for-unit-test
Sep 2, 2022
b97a7f3
delete incRef and decRef
Sep 3, 2022
32733e6
Fix static property
Sep 3, 2022
c3d1faa
Polish warp code
Sep 3, 2022
ad2e6f0
Fix setAttr and some functions memory leak
Sep 4, 2022
00310b6
Fix extra Py_DECREF
Sep 4, 2022
4cf028a
detail modified
Sep 4, 2022
c836f15
Add more Nativetest
Sep 6, 2022
b0ed362
Simple modification
Sep 6, 2022
98e2215
Try to fix memory leak
Sep 6, 2022
84c2660
Fix wrong decref
yqs112358 Feb 26, 2023
3518d61
Fix ref count problems about PyTuple_SetItem
yqs112358 Feb 26, 2023
1440370
skip unsolved problem and leave todo
yqs112358 Feb 26, 2023
42d83ec
fix array set ref count bug and some other small bugs
yqs112358 Feb 26, 2023
c7fb4bd
Fix ref count bug caused function return crash
yqs112358 Feb 27, 2023
b1642e8
add native test code for python
yqs112358 Feb 27, 2023
fff060e
add 2 todos
yqs112358 Feb 28, 2023
8c3b8c6
Fix test problems
yqs112358 Feb 28, 2023
61ca927
Fix callImpl to consider thiz
yqs112358 Feb 28, 2023
a07dac8
Check exception after call function
yqs112358 Feb 28, 2023
acbddec
Finish demo unit test for py
yqs112358 Feb 28, 2023
7c04da3
change BytesBuffer type to bytearray and adapt unittest
yqs112358 Feb 28, 2023
cdaa79a
finish ByteBuffer and pass UnitTest
yqs112358 Feb 28, 2023
7d04b4b
fix and finish Weak and Global class
yqs112358 Mar 1, 2023
54e8b49
Check and fix all ref count bugs about Local class
yqs112358 Mar 1, 2023
38fa31d
reconstruct Global&Weak storage to support cleanup
yqs112358 Mar 2, 2023
b2e95d7
fix construct from cpp
yqs112358 Mar 2, 2023
7cffe72
finish more tests for python
yqs112358 Mar 2, 2023
eac8a9e
support CPP exception -> Python
yqs112358 Mar 2, 2023
41feb23
remove message in queue when engine shutdown
yqs112358 Mar 3, 2023
c648d4f
Reconstruct exception class
yqs112358 Mar 3, 2023
c54bb58
finish getInternalStore and support custom object __dict__
yqs112358 Mar 5, 2023
050075e
rename a helper func
yqs112358 Mar 5, 2023
ca3dcb7
small fix
yqs112358 Mar 5, 2023
6923b7d
Add docs about weak ref problem
yqs112358 Mar 5, 2023
954f0ca
May fix wrong thiz
yqs112358 Mar 6, 2023
80155cb
disable thiz redirction in Function because Py does not support
yqs112358 Mar 6, 2023
7c07a74
Add some docs
yqs112358 Mar 6, 2023
6540dc3
Fix EngineScope completely and add more comments
yqs112358 Mar 6, 2023
aa51bdf
Fix a bug in exitscope
yqs112358 Mar 7, 2023
7640eb6
Finish basic logic
yqs112358 Mar 7, 2023
2b3336f
try to fix
yqs112358 Mar 8, 2023
a1e14f6
Miss-understand EngineScope! Finally fix it
yqs112358 Mar 8, 2023
da1f15d
Fix ref bug of Py_None
yqs112358 Mar 8, 2023
7627eb3
add some comments
yqs112358 Mar 8, 2023
31bcda1
More fix about refs of Global and Weak
yqs112358 Mar 8, 2023
8f79009
fix namespace bug cause crash
yqs112358 Mar 9, 2023
b965f8a
Fix unittest and leave a todo
yqs112358 Mar 9, 2023
80eca22
Fix instanceOf
yqs112358 Mar 9, 2023
1720ba5
add some comment
Mar 9, 2023
924d882
small fix
yqs112358 Mar 9, 2023
8100361
Fix constructor from CPP
yqs112358 Mar 9, 2023
df31d3c
Fix Global and Weak for unexpected no destroy
yqs112358 Mar 10, 2023
bc23978
Fix name of unittest
yqs112358 Mar 10, 2023
0024e09
Fix destroy bug
yqs112358 Mar 10, 2023
c67f581
Add weakref callback to avoid refusing creation
yqs112358 Mar 10, 2023
f6b4d55
Fix function callback leak
yqs112358 Mar 10, 2023
51d96ba
Fix error of Local ref
yqs112358 Mar 11, 2023
f55e38c
Fix bad UnitTest
yqs112358 Mar 11, 2023
a4777bd
Fix a serious bug of creating custom type objects
yqs112358 Mar 11, 2023
6c35752
add docs
yqs112358 Mar 11, 2023
f7677e1
Add tracers and some doc
yqs112358 Mar 11, 2023
1a5c32e
Small fix about eval judgement
yqs112358 Mar 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
strategy:
fail-fast: false
matrix:
backends: [ V8, JavaScriptCore, Lua, Empty ]
backends: [ V8, JavaScriptCore, Lua, Python, Empty ]
build_type:
- Debug
- Release
Expand Down
22 changes: 22 additions & 0 deletions backend/JavaScriptCore/JscEngine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "../../src/Native.hpp"
#include "JscEngine.hpp"
#include "JscHelper.h"
#include "../../src/utils/Helper.hpp"

namespace script::jsc_backend {

Expand Down Expand Up @@ -177,6 +178,27 @@ script::Local<script::Value> JscEngine::eval(const script::Local<script::String>
return eval(script, {});
}

Local<Value> JscEngine::loadFile(const Local<String>& scriptFile) {
if(scriptFile.toString().empty())
throw Exception("script file no found");
Local<Value> content = internal::readAllFileContent(scriptFile);
if(content.isNull())
throw Exception("can't load script file");

std::string sourceFilePath = scriptFile.toString();
std::size_t pathSymbol = sourceFilePath.rfind("/");
if(pathSymbol != -1)
sourceFilePath = sourceFilePath.substr(pathSymbol + 1);
else
{
pathSymbol = sourceFilePath.rfind("\\");
if(pathSymbol != -1)
sourceFilePath = sourceFilePath.substr(pathSymbol + 1);
}
Local<String> sourceFileName = String::newString(sourceFilePath);
return eval(content.asString(), sourceFileName);
}

std::shared_ptr<utils::MessageQueue> JscEngine::messageQueue() { return messageQueue_; }

void JscEngine::gc() {
Expand Down
2 changes: 2 additions & 0 deletions backend/JavaScriptCore/JscEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class JscEngine : public ::script::ScriptEngine {
Local<Value> eval(const Local<String>& script) override;
using ScriptEngine::eval;

Local<Value> loadFile(const Local<String>& scriptFile) override;

std::shared_ptr<utils::MessageQueue> messageQueue() override;

void gc() override;
Expand Down
2 changes: 1 addition & 1 deletion backend/JavaScriptCore/JscUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ std::string_view StringHolder::stringView() const {
std::string StringHolder::string() const {
jsc_backend::initString(internalHolder_);
internalHolder_.inited = false;
return std::move(internalHolder_.stringContent);
return internalHolder_.stringContent;
}

#if defined(__cpp_char8_t)
Expand Down
22 changes: 22 additions & 0 deletions backend/Lua/LuaEngine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "LuaHelper.hpp"
#include "LuaReference.hpp"
#include "LuaScope.hpp"
#include "../../src/utils/Helper.hpp"

// ref https://www.lua.org/manual/5.1/manual.html
// https://www.lua.org/wshop14/Zykov.pdf
Expand Down Expand Up @@ -259,6 +260,27 @@ Local<Value> LuaEngine::eval(const Local<String>& script, const Local<Value>& so
return lua_backend::callFunction({}, {}, 0, nullptr);
}

Local<Value> LuaEngine::loadFile(const Local<String>& scriptFile) {
if(scriptFile.toString().empty())
throw Exception("script file no found");
Local<Value> content = internal::readAllFileContent(scriptFile);
if(content.isNull())
throw Exception("can't load script file");

std::string sourceFilePath = scriptFile.toString();
std::size_t pathSymbol = sourceFilePath.rfind("/");
if(pathSymbol != -1)
sourceFilePath = sourceFilePath.substr(pathSymbol + 1);
else
{
pathSymbol = sourceFilePath.rfind("\\");
if(pathSymbol != -1)
sourceFilePath = sourceFilePath.substr(pathSymbol + 1);
}
Local<String> sourceFileName = String::newString(sourceFilePath);
return eval(content.asString(), sourceFileName);
}

Arguments LuaEngine::makeArguments(LuaEngine* engine, int stackBase, size_t paramCount,
bool isInstanceFunc) {
lua_backend::ArgumentsData argumentsData{engine, stackBase, paramCount, isInstanceFunc};
Expand Down
2 changes: 2 additions & 0 deletions backend/Lua/LuaEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class LuaEngine : public ScriptEngine {
Local<Value> eval(const Local<String>& script) override;
using ScriptEngine::eval;

Local<Value> loadFile(const Local<String>& scriptFile) override;

std::shared_ptr<utils::MessageQueue> messageQueue() override;

void gc() override;
Expand Down
37 changes: 33 additions & 4 deletions backend/Lua/LuaLocalReference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,28 @@ void ensureNonnull(int index) {
throw Exception("NullPointerException");
}

bool judgeIsArray(int index)
{
auto lua = currentLua();
int currectArrIndex = 0;

lua_pushnil(lua);

while (lua_next(lua, index))
{
// Copy current key and judge it's type
lua_pushvalue(lua, -2);
if(!lua_isnumber(lua,-1) || lua_tonumber(lua,-1) != ++currectArrIndex)
{
lua_pop(lua, 3);
return false;
}
lua_pop(lua, 2);
}
return true;
}


} // namespace lua_backend

#define REF_IMPL_BASIC_FUNC(ValueType) \
Expand Down Expand Up @@ -149,8 +171,11 @@ ValueKind Local<Value>::getKind() const {
} else if (isByteBuffer()) {
return ValueKind::kByteBuffer;
} else if (type == LUA_TTABLE) {
// lua don't have array type, the are all tables
return ValueKind::kObject;
// Traverse the table to judge whether it is an array
if(isArray())
return ValueKind::kArray;
else
return ValueKind::kObject;
} else {
return ValueKind::kUnsupported;
}
Expand All @@ -176,7 +201,11 @@ bool Local<Value>::isFunction() const {
return val_ != 0 && lua_type(lua_backend::currentLua(), val_) == LUA_TFUNCTION;
}

bool Local<Value>::isArray() const { return isObject(); }
bool Local<Value>::isArray() const {
if(val_ == 0 || lua_type(lua_backend::currentLua(), val_) != LUA_TTABLE)
return false;
return lua_backend::judgeIsArray(val_);
}

bool Local<Value>::isByteBuffer() const {
auto engine = lua_backend::currentEngine();
Expand Down Expand Up @@ -437,4 +466,4 @@ void Local<ByteBuffer>::commit() const {}

void Local<ByteBuffer>::sync() const {}

} // namespace script
} // namespace script
17 changes: 16 additions & 1 deletion backend/Python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
message(FATAL_ERROR "${SCRIPTX_BACKEND} is to be implemented.")
target_sources(ScriptX PRIVATE
${CMAKE_CURRENT_LIST_DIR}/PyEngine.cc
${CMAKE_CURRENT_LIST_DIR}/PyEngine.h
${CMAKE_CURRENT_LIST_DIR}/PyException.cc
${CMAKE_CURRENT_LIST_DIR}/PyHelper.h
${CMAKE_CURRENT_LIST_DIR}/PyHelper.hpp
${CMAKE_CURRENT_LIST_DIR}/PyHelper.cc
${CMAKE_CURRENT_LIST_DIR}/PyLocalReference.cc
${CMAKE_CURRENT_LIST_DIR}/PyNative.cc
${CMAKE_CURRENT_LIST_DIR}/PyNative.hpp
${CMAKE_CURRENT_LIST_DIR}/PyReference.hpp
${CMAKE_CURRENT_LIST_DIR}/PyScope.h
${CMAKE_CURRENT_LIST_DIR}/PyScope.cc
${CMAKE_CURRENT_LIST_DIR}/PyUtils.cc
${CMAKE_CURRENT_LIST_DIR}/PyValue.cc
)
Loading