Skip to content

Commit

Permalink
修复Android、Unity3D中提早释放Function问题
Browse files Browse the repository at this point in the history
Former-commit-id: 4f4e3f3f24e2e067111ea897bee5950934801129
  • Loading branch information
vimfung committed May 31, 2017
1 parent f7c26af commit 90dbb74
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
16 changes: 8 additions & 8 deletions Sample/Android/app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
Expand All @@ -85,6 +77,14 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
Expand Down
13 changes: 13 additions & 0 deletions Source/lua-common/LuaDataExchanger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,19 @@ void LuaDataExchanger::getLuaObject(LuaObject *object)
}
}

void LuaDataExchanger::setLuaObject(int stackIndex, const std::string &linkId)
{
lua_State *state = _context -> getLuaState();

beginGetVarsTable();

//放入对象到_vars_表中
lua_pushvalue(state, stackIndex);
lua_setfield(state, -2, linkId.c_str());

endGetVarsTable();
}

void LuaDataExchanger::retainLuaObject(LuaObject *object)
{
if (object != NULL)
Expand Down
8 changes: 8 additions & 0 deletions Source/lua-common/LuaDataExchanger.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ namespace cn {
*/
void getLuaObject(LuaObject *object);

/**
* 设置Lua对象
*
* @param stackIndex 栈索引
* @param linkId 连接标识
*/
void setLuaObject(int stackIndex, const std::string &linkId);

/**
* 保留对象对应在Lua中的引用
*
Expand Down
2 changes: 2 additions & 0 deletions Source/lua-common/LuaFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ LuaFunction::LuaFunction(LuaContext *context, int index)
_context = context;
_linkId = StringUtils::format("%p", this);

_context -> getDataExchanger() -> setLuaObject(index, _linkId);

LuaValue *value = LuaValue::FunctionValue(this);
_context->retainValue(value);
value -> release();
Expand Down

0 comments on commit 90dbb74

Please sign in to comment.