Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
东方怂天
xLua
提交
7c5f7829
X
xLua
项目概览
东方怂天
/
xLua
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
xLua
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
7c5f7829
编写于
8月 10, 2017
作者:
J
johnche(车雄生)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
2.1.9发布
上级
113ebdb8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
478 addition
and
8 deletion
+478
-8
Assets/XLua/CHANGELOG.txt
Assets/XLua/CHANGELOG.txt
+4
-4
Assets/XLua/Examples/01_Helloworld/Helloworld.cs
Assets/XLua/Examples/01_Helloworld/Helloworld.cs
+473
-3
Assets/XLua/Examples/01_Helloworld/Helloworld.unity
Assets/XLua/Examples/01_Helloworld/Helloworld.unity
+0
-0
README.md
README.md
+1
-1
未找到文件。
Assets/XLua/CHANGELOG.txt
浏览文件 @
7c5f7829
v2.1.9
[待发布]
v2.1.9
2017年8月10日
新增特性
1、新增最小生成模式,可以节省50%的text段空间;
1、新增最小生成模式
(通过GEN_CODE_MINIMIZE切换)
,可以节省50%的text段空间;
2、新增xlua.util.createdelegate,支持在lua直接用C#函数创建delegate而不需要通过lua适配;
3、xlua.private_accessible支持public int Prop { get; private set; }
4、新增 xlua.getmetatable、
xlua.setmetatable、xlua.setclass、xlua.genaccessor,用以支持lua使用C#类型直接在lua侧完成;
4、新增 xlua.getmetatable、xlua.setmetatable、xlua.setclass、xlua.genaccessor,用以支持lua使用C#类型直接在lua侧完成;
5、反射下扩展方法的支持;
优化
工程
优化
1、加入travis持续集成;
变更
...
...
Assets/XLua/Examples/01_Helloworld/Helloworld.cs
浏览文件 @
7c5f7829
...
...
@@ -8,17 +8,487 @@
using
UnityEngine
;
using
XLua
;
using
System
;
using
System.Reflection
;
using
System.Linq
;
using
System.Collections.Generic
;
public
class
BBClass
{
public
void
AB
()
{
UnityEngine
.
Debug
.
Log
(
"BBClass.AB"
);
}
public
virtual
void
CD
()
{
UnityEngine
.
Debug
.
Log
(
"BBClass.CD"
);
}
}
public
class
HelloCall
{
public
int
Add
(
int
a
,
int
b
)
{
return
a
+
b
;
}
public
int
Add
(
int
a
)
{
return
a
;
}
}
public
class
DDClass
:
BBClass
{
public
void
AB
()
{
UnityEngine
.
Debug
.
Log
(
"DDClass.AB"
);
}
public
override
void
CD
()
{
UnityEngine
.
Debug
.
Log
(
"DDClass.CD"
);
}
}
[
CSharpCallLua
]
public
delegate
void
AAA
(
System
.
IntPtr
p
,
System
.
UIntPtr
p2
,
out
object
o
);
public
delegate
void
MyAction
();
public
class
TestTestTest
{
~
TestTestTest
()
{
Debug
.
Log
(
"TestTestTest"
);
}
}
public
interface
IHehe
{
void
Foo
();
}
[
LuaCallCSharp
]
public
struct
Hehe
:
IHehe
{
public
void
Foo
()
{
}
}
[
LuaCallCSharp
]
public
static
class
TestExtension
{
public
static
void
AddInput
<
U
,
V
>(
this
U
p1
,
V
p2
)
where
U
:
struct
,
IHehe
where
V
:
struct
,
IHehe
{
}
public
static
void
Des
<
U
>(
this
U
p1
)
where
U
:
struct
,
IHehe
{
}
}
public
class
ABCDE
{
public
int
AAA
;
public
void
Foo
(
int
a
)
{
Debug
.
Log
(
"Abc.Foo :"
+
a
+
", AAA"
+
a
);
}
public
static
void
SFoo
(
int
a
)
{
Debug
.
Log
(
"Abc.SFoo :"
+
a
);
}
void
Bar
(
double
b
)
{
}
public
static
Delegate
CreateDelegate
(
Type
type
,
object
firstArgument
,
MethodInfo
method
)
{
return
Delegate
.
CreateDelegate
(
type
,
firstArgument
,
method
);
}
}
public
static
class
CFG
{
[
LuaCallCSharp
]
public
static
List
<
Type
>
a
=
new
List
<
Type
>()
{
typeof
(
Delegate
),
typeof
(
ABCDE
)
};
}
public
delegate
void
MyDelegate
(
int
a
);
[
LuaCallCSharp
]
public
class
MyInt
{
private
int
m_value
;
public
int
Value
{
get
{
return
m_value
;
}
set
{
m_value
=
value
;
}
}
public
MyInt
(
int
value
)
{
m_value
=
value
;
}
public
static
MyInt
operator
&(
MyInt
a
,
MyInt
b
)
{
MyInt
c
=
new
MyInt
(
0
);
c
.
Value
=
a
.
Value
&
b
.
Value
;
return
c
;
}
public
static
MyInt
operator
|(
MyInt
a
,
MyInt
b
)
{
MyInt
c
=
new
MyInt
(
0
);
c
.
Value
=
a
.
Value
|
b
.
Value
;
return
c
;
}
public
static
MyInt
operator
^(
MyInt
a
,
MyInt
b
)
{
MyInt
c
=
new
MyInt
(
0
);
c
.
Value
=
a
.
Value
^
b
.
Value
;
return
c
;
}
public
static
MyInt
operator
~(
MyInt
a
)
{
MyInt
c
=
new
MyInt
(
0
);
c
.
Value
=
~
a
.
Value
;
return
c
;
}
public
static
MyInt
operator
<<(
MyInt
a
,
int
s
)
{
MyInt
c
=
new
MyInt
(
0
);
c
.
Value
=
a
.
Value
<<
s
;
return
c
;
}
public
static
MyInt
operator
>>(
MyInt
a
,
int
s
)
{
MyInt
c
=
new
MyInt
(
0
);
c
.
Value
=
a
.
Value
>>
s
;
return
c
;
}
}
enum
LargeEnum
{
A
=
1
}
[
LuaCallCSharp
]
public
class
Helloworld
:
MonoBehaviour
{
static
public
string
CCC
;
public
const
string
a
=
"test"
;
public
static
int
?
AAA
=
null
;
public
static
void
ToMyType
(
object
number
,
ref
object
CNum
)
{
}
public
static
bool
SetStruct
<
T
>(
ref
T
currentValue
,
T
newValue
)
where
T
:
struct
{
return
true
;
}
public
static
bool
SetClass
<
T
>(
ref
T
currentValue
,
T
newValue
)
where
T
:
class
{
return
true
;
}
public
int
PP
{
get
;
private
set
;
}
[
Obsolete
(
"hehe"
)]
public
void
T1
()
{
}
[
Obsolete
(
"hehe2"
,
true
)]
public
void
T2
()
{
}
public
System
.
Action
act
;
public
MyDelegate
md
;
public
void
TestMd
()
{
md
(
100
);
}
public
void
Foo
()
{
if
(
XLua
.
HotfixDelegateBridge
.
xlua_get_hotfix_flag
(
0
))
{
Debug
.
Log
(
"Bar"
);
}
Debug
.
Log
(
"Foo"
);
}
public
void
CallCC
(
LuaTable
scriptEnv
)
{
Action
cc
=
scriptEnv
.
Get
<
Action
>(
"cc"
);
cc
();
cc
=
null
;
}
// Use this for initialization
void
Start
()
{
LuaEnv
luaenv
=
new
LuaEnv
();
luaenv
.
DoString
(
"CS.UnityEngine.Debug.Log('hello world')"
);
Debug
.
Log
(
typeof
(
Dictionary
<
string
,
UnityEngine
.
Object
>).
AssemblyQualifiedName
);
foreach
(
var
t
in
typeof
(
DG
.
Tweening
.
Core
.
TweenerCore
<,,>).
GetGenericArguments
())
{
Debug
.
Log
(
t
);
foreach
(
var
c
in
t
.
GetGenericParameterConstraints
())
{
Debug
.
Log
(
"c------"
+
c
);
}
Debug
.
Log
(
"========"
+
t
.
GenericParameterAttributes
);
}
Debug
.
Log
(
"++++++++++++++++++++++++++++++++++"
);
foreach
(
var
t
in
typeof
(
ITestConstrains
<>).
GetGenericArguments
())
{
Debug
.
Log
(
t
);
foreach
(
var
c
in
t
.
GetGenericParameterConstraints
())
{
Debug
.
Log
(
"c------"
+
c
);
}
Debug
.
Log
(
"========"
+
t
.
GenericParameterAttributes
);
}
//typeof(ABCDE).GetMethod()
luaenv
.
Global
.
Set
(
"self"
,
this
);
luaenv
.
DoString
(
@"
local m = typeof(CS.ABCDE):GetMethod('Foo', {typeof(CS.System.Int32)})
print(m)
m = typeof(CS.ABCDE):GetMethod('Bar', {typeof(CS.System.Double)})
print(m)
m = typeof(CS.ABCDE):GetMethod('Bar', CS.System.Reflection.BindingFlags.Public | CS.System.Reflection.BindingFlags.NonPublic
| CS.System.Reflection.BindingFlags.Instance | CS.System.Reflection.BindingFlags.Static)
print(m)
m = typeof(CS.ABCDE):GetMethod('Bar', CS.System.Reflection.BindingFlags.Public | CS.System.Reflection.BindingFlags.NonPublic
| CS.System.Reflection.BindingFlags.Instance | CS.System.Reflection.BindingFlags.Static, nil, {typeof(CS.System.Double)}, nil)
print(m)
print((CS.MyInt(2) & CS.MyInt(3)).Value)
print((CS.MyInt(2) | CS.MyInt(3)).Value)
print((CS.MyInt(2) ~ CS.MyInt(3)).Value)
print((~ CS.MyInt(3)).Value)
print((CS.MyInt(3) >> 1).Value)
print((CS.MyInt(3) << 1).Value)
print(CS.System.Reflection.BindingFlags.Public, CS.System.Reflection.BindingFlags.NonPublic)
print(CS.System.Reflection.BindingFlags.Public | CS.System.Reflection.BindingFlags.NonPublic)
local util = require 'xlua.util'
local abcd = CS.ABCDE()
local d = util.createdelegate(CS.MyDelegate, abcd, CS.ABCDE, 'Foo', {typeof(CS.System.Int32)})
local d2 = util.createdelegate(CS.MyDelegate, nil, CS.ABCDE, 'SFoo', {typeof(CS.System.Int32)})
self.md = d + d2
self:TestMd()
--print(CS.System.Type.GetType('System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[UnityEngine.Object, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'))
--print(CS.System.Type.GetType('System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[UnityEngine.Object, UnityEngine]], mscorlib'))
--print(CS.System.Type.GetType('System.Collections.Generic.Dictionary`2[System.String,[UnityEngine.Object, UnityEngine]]'))
--print(xlua.getmetatable('System.Collections.Generic.Dictionary`2[System.String,[UnityEngine.Object, UnityEngine]]'))
--xlua.getmetatable(CS.System.Collections.Generic['Dictionary`2[System.String,[UnityEngine.Object, UnityEngine]]'])
"
);
//typeof(ABCDE).GetMethod()
luaenv
.
Dispose
();
}
/*var m = typeof(TestExtension).GetMethod("AddInput");
foreach(var p in m.GetParameters())
{
foreach(var c in p.Get)
}*/
//LuaEnv luaenv = new LuaEnv();
//luaenv.DoString("local a = CS.UnityEngine.Quaternion(0,0,0) ");
//luaenv.Global.Set("self", this);
//Debug.Log(luaenv.Global.ContainsKey("self"));
//Debug.Log(luaenv.Global.ContainsKey("self1"));
//for(int i = 0; i< 100000;i++)
//{
// luaenv.Global.ContainsKey("self");
// luaenv.Global.ContainsKey("self1");
//}
//Debug.Log(luaenv.Global.ContainsKey("self"));
//Debug.Log(luaenv.Global.ContainsKey("self1"));
/*
LuaTable scriptEnv = luaenv.NewTable();
LuaTable meta = luaenv.NewTable();
meta.Set("__index", luaenv.Global);
scriptEnv.SetMetaTable(meta);
meta.Dispose();*/
//var tg = new TestGC(444);
//luaenv.Global.Set("a", tg);
//luaenv.Global.Set<string, object>("a", null);
//tg = null;
//new Int32();
//luaenv.Global.Set("self", this);
//luaenv.Global.Set("l", new List<int>());
//luaenv.Global.Set("d1", new Dictionary<int,int>());
//luaenv.Global.Set("d2", new Dictionary<string, int>());
//luaenv.Global.Set("d3", new Dictionary<string, string>());
/*luaenv.DoString(@"
CS.UnityEngine.Debug.Log('hello world')
--local o = CS.UnityEngine.GameObject.Find('Main Camera')
--o:StopAnimation()
--print(self.PP)
--local util = require 'xlua.util'
--xlua.private_accessible(CS.Helloworld)
--self.PP = 10
--print(self.PP)
--l:Add(1)
--d1:Add(2, 5)
--d2:Add('h', 4)
--d3:Add('j', 'o')
--iprint('hehe', 1, 2, 3)
");*/
//UnityEngine.GameObject.
//LuaFunction geta = luaenv.Global.Get<LuaFunction>("ReturnA");
//Debug.Log(geta.Call()[0]);
//LuaTable tbl = luaenv.NewTable();
//geta.SetEnv(tbl);
//Debug.Log(geta.Call()[0]);
//Action cc = scriptEnv.Get<Action>("cc");
//cc();
//cc = null;
//CallCC(scriptEnv);
//LuaFunction cc = luaenv.Global.Get<LuaFunction>("cc");
//luaenv.PrintTop();
//cc.Call(1);
//cc.Call(3214);
//luaenv.PrintTop();
//cc.Call(2435423);
//luaenv.PrintTop();
//cc.Call(43151);
//luaenv.PrintTop();
//cc.Dispose();
//scriptEnv.Dispose();
//System.GC.Collect();
//System.GC.WaitForPendingFinalizers();
//luaenv.Tick();
//luaenv.FullGc();
//System.GC.Collect();
//System.GC.WaitForPendingFinalizers();
////luaenv.FullGc();
//Debug.Log("-------------------");
//luaenv.Dispose();
//UnityEngine.Debug.Log("a:" + (typeof(int) == typeof(int?)));
//var t = new UnsafeTest();
//t.UnsafeSet(2, 10);
//Debug.Log(t.UnsafeGet(2));
//BBClass bb = new DDClass();
//bb.AB();
//bb.CD();
//(bb as DDClass).AB();
//(bb as DDClass).CD();
//foreach(var type in Assembly.Load("Assembly-CSharp").GetTypes())
//{
// var bindingAttrOfMethod = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.NonPublic;
// //
// if (type.Namespace != null && type.Namespace.StartsWith("XLua") &&
// type.GetConstructors(bindingAttrOfMethod).Any(m => m.Name == ".cctor" && m.IsSpecialName))
// {
// Debug.LogWarning(type.ToString() + " ok??");
// foreach (var method in (type.GetMethods(bindingAttrOfMethod).Where(m => m.IsStatic && !m.IsConstructor)))
// {
// Debug.Log("type:" + method.DeclaringType + ",method:" + method);
// }
// }
// else
// {
// //Debug.Log(type.ToString() + " ok");
// }
//}
//Array arr = new int[] { 1 };
//Debug.Log(arr.GetValue(1));
//var type = typeof(Dictionary<,>);
//Debug.Log("B:" + type.IsGenericTypeDefinition);
//foreach(var garg in type.GetGenericArguments())
//{
// Debug.Log(garg + ",p:"+ garg.DeclaringType+ ",m:" + garg.DeclaringMethod);
//}
//Debug.Log("B:" + typeof(System.Collections.Generic.IEqualityComparer<>));
//Debug.Log("B:" + typeof(Dictionary<int, int>));
}
// Update is called once per frame
void
Update
()
{
if
(
getInjection
(
1
)
!=
null
)
{
var
injection
=
getInjection
(
1
)
as
MyAction
;
injection
();
}
}
static
object
[]
injectionList
=
null
;
object
getInjection
(
int
idx
)
{
if
(
injectionList
==
null
||
idx
>=
injectionList
.
Length
)
{
return
null
;
}
else
{
return
injectionList
[
idx
];
}
}
}
[
Hotfix
]
public
class
ObjectPool
{
public
static
ObjectPool
get_Instance
()
{
return
null
;
}
}
Assets/XLua/Examples/01_Helloworld/Helloworld.unity
浏览文件 @
7c5f7829
无法预览此类型文件
README.md
浏览文件 @
7c5f7829
![](
Assets/XLua/Doc/xLua.png
)
[
![license
](
http://img.shields.io/badge/license-MIT-blue.svg
)
](https://github.com/Tencent/xLua/blob/master/LICENSE.TXT)
[
![release
](
https://img.shields.io/badge/release-v2.1.
8
-blue.svg
)
](https://github.com/Tencent/xLua/releases)
[
![release
](
https://img.shields.io/badge/release-v2.1.
9
-blue.svg
)
](https://github.com/Tencent/xLua/releases)
[
![PRs Welcome
](
https://img.shields.io/badge/PRs-welcome-blue.svg
)
](https://github.com/Tencent/xLua/pulls)
[
![Build status
](
https://travis-ci.org/Tencent/xLua.svg?branch=master
)
](https://travis-ci.org/Tencent/xLua)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录