Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

当基类有静态变量时,派生类会new失败 #45

Closed
mybios opened this issue Jul 3, 2018 · 1 comment
Closed

当基类有静态变量时,派生类会new失败 #45

mybios opened this issue Jul 3, 2018 · 1 comment

Comments

@mybios
Copy link
Contributor

mybios commented Jul 3, 2018

`
using System;
using UnityEngine;

namespace CSLua
{

public class TestBase
{
    public static Func<string, string> delegateSyncLoadUI = null;
}
public class TestClass : TestBase
{

}

public class Test1 : CSLua.LuaPage
{

}
public sealed class GameMain : MonoBehaviour {

public void Awake()
    {
        new TestClass();
}

}
}

`

当使用以上代码运行时,发现new TestClass()会失败。

编译后代码:
`
-- Generated by CSharp.lua Compiler 1.1.0
local System = System
local CSLua
System.usingDeclare(function (global)
CSLua = global.CSLua
end)
System.namespace("CSLua", function (namespace)
namespace.class("TestBase", function (namespace)
local staticCtor
staticCtor = function (this)
this.delegateSyncLoadUI = nil
end
return {
staticCtor = staticCtor
}
end)
namespace.class("TestClass", function (namespace)
local ctor
ctor = function (this)
this.base.ctor(this)
end
return {
inherits = function (global)
return {
global.CSLua.TestBase
}
end,
ctor = ctor
}
end)

namespace.class("Test1", function (namespace)
local ctor
ctor = function (this)
this.base.ctor(this)
end
return {
inherits = function (global)
return {
global.CSLua.LuaPage
}
end,
ctor = ctor
}
end)
namespace.class("GameMain", function (namespace)
local Awake
Awake = function (this)
CSLua.TestClass()
end
return {
inherits = function (global)
return {
global.UnityEngine.MonoBehaviour
}
end,
Awake = Awake
}
end)
end)

`

报错信息:
LuaException: D:/OWM_Client3/Assets/CSharpLua/Lua/CompiledScripts/CSLua/GameMain.lua:50: attempt to call field 'TestClass' (a table value)
stack traceback:
D:/OWM_Client3/Assets/CSharpLua/Lua/CompiledScripts/CSLua/GameMain.lua:50: in function 'Awake'
D:/OWM_Client3/Assets/CSharpLua/Lua/UnityAdapter.lua:240: in function 'ctor'
D:/OWM_Client3/Assets/CSharpLua/Lua/CoreSystemLua/CoreSystem/Core.lua:48: in function <D:/OWM_Client3/Assets/CSharpLua/Lua/CoreSystemLua/CoreSystem/Core.lua:46>

@mybios
Copy link
Contributor Author

mybios commented Jul 3, 2018

当静态变量换成bool类型时,报错也是一样的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant