mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-26 18:26:23 +00:00
update
This commit is contained in:
6
luban_examples/Projects/Lua_Unity_xlua_bin/.vsconfig
Normal file
6
luban_examples/Projects/Lua_Unity_xlua_bin/.vsconfig
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"version": "1.0",
|
||||
"components": [
|
||||
"Microsoft.VisualStudio.Workload.ManagedGame"
|
||||
]
|
||||
}
|
File diff suppressed because it is too large
Load Diff
1020
luban_examples/Projects/Lua_Unity_xlua_bin/Assembly-CSharp.csproj
Normal file
1020
luban_examples/Projects/Lua_Unity_xlua_bin/Assembly-CSharp.csproj
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00f1b512f9b094c48a724a7cb129ff08
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11eeb1f91b39d9b4ea05d2c39ce57027
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
3823
luban_examples/Projects/Lua_Unity_xlua_bin/Assets/Lua/Gen/schema.lua
Normal file
3823
luban_examples/Projects/Lua_Unity_xlua_bin/Assets/Lua/Gen/schema.lua
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f95d32285b9d1a40910bb4cc1166b31
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
159
luban_examples/Projects/Lua_Unity_xlua_bin/Assets/Lua/Main.lua
Normal file
159
luban_examples/Projects/Lua_Unity_xlua_bin/Assets/Lua/Main.lua
Normal file
@@ -0,0 +1,159 @@
|
||||
local require = require
|
||||
local print = print
|
||||
|
||||
local C = {}
|
||||
|
||||
local require = require
|
||||
local assert = assert
|
||||
local pairs = pairs
|
||||
local print = print
|
||||
local tinsert = table.insert
|
||||
local tconcat = table.concat
|
||||
|
||||
local function ttostring2(x, result)
|
||||
local t = type(x)
|
||||
if t == "table" then
|
||||
tinsert(result, "{")
|
||||
for k, v in pairs(x) do
|
||||
tinsert(result, tostring(k))
|
||||
tinsert(result, "=")
|
||||
ttostring2(v, result)
|
||||
tinsert(result, ",")
|
||||
end
|
||||
|
||||
tinsert(result, "}")
|
||||
elseif t == "string" then
|
||||
tinsert(result, x)
|
||||
else
|
||||
tinsert(result, tostring(x))
|
||||
end
|
||||
end
|
||||
|
||||
function ttostring(t)
|
||||
local out = {}
|
||||
ttostring2(t, out)
|
||||
return tconcat(out)
|
||||
end
|
||||
|
||||
|
||||
ByteBuf = CS.Bright.Serialization.ByteBuf
|
||||
|
||||
local byteBufIns = ByteBuf()
|
||||
|
||||
local byteBufFuns = {
|
||||
readBool = byteBufIns.ReadBool,
|
||||
writeBool = byteBufIns.WriteBool,
|
||||
readByte = byteBufIns.ReadByte,
|
||||
writeByte = byteBufIns.WriteByte,
|
||||
readShort = byteBufIns.ReadShort,
|
||||
writeShort = byteBufIns.WriteShort,
|
||||
readFshort = byteBufIns.ReadFshort,
|
||||
writeInt = byteBufIns.WriteInt,
|
||||
readInt = byteBufIns.ReadInt,
|
||||
writeFint = byteBufIns.WriteFint,
|
||||
readFint = byteBufIns.ReadFint,
|
||||
readLong = byteBufIns.ReadLong,
|
||||
writeLong = byteBufIns.WriteLong,
|
||||
readFlong = byteBufIns.ReadFlong,
|
||||
writeFlong = byteBufIns.WriteFlong,
|
||||
readFloat = byteBufIns.ReadFloat,
|
||||
writeFloat = byteBufIns.WriteFloat,
|
||||
readDouble = byteBufIns.ReadDouble,
|
||||
writeDouble = byteBufIns.WriteDouble,
|
||||
readSize = byteBufIns.ReadSize,
|
||||
writeSize = byteBufIns.WriteSize,
|
||||
readString = byteBufIns.ReadString,
|
||||
writeString = byteBufIns.WriteString,
|
||||
readBytes = byteBufIns.ReadBytes,
|
||||
writeBytes = byteBufIns.WriteBytes
|
||||
}
|
||||
|
||||
function read_file_all_bytes(fileName)
|
||||
local file = io.open(fileName, "rb")
|
||||
local bytes = file:read("*a")
|
||||
file:close()
|
||||
return bytes
|
||||
end
|
||||
|
||||
|
||||
local enumDefs = {}
|
||||
local constDefs = {}
|
||||
|
||||
local tables = {}
|
||||
|
||||
---@param configPath string
|
||||
---@param configFileloader function
|
||||
function Load(typeDefs, configFileloader)
|
||||
|
||||
local configPath = CS.UnityEngine.Application.dataPath .. "/../../GenerateDatas/bytes/"
|
||||
|
||||
enumDefs = typeDefs.enums
|
||||
constDefs = typeDefs.consts
|
||||
|
||||
local buf = ByteBuf()
|
||||
local tableDefs = typeDefs.tables
|
||||
local beanDefs = typeDefs.beans
|
||||
for _, t in pairs(tableDefs) do
|
||||
--print("load table:", ttostring(t))
|
||||
buf:Clear()
|
||||
buf:WriteBytesWithoutSize(read_file_all_bytes(configPath .. "/" .. t.file .. ".bytes"))
|
||||
|
||||
local valueType = beanDefs[t.value_type]
|
||||
local mode = t.mode
|
||||
|
||||
local tableDatas
|
||||
if mode == "map" then
|
||||
tableDatas = {}
|
||||
local index = t.index
|
||||
for i = 1, buf:ReadSize() do
|
||||
local v = valueType._deserialize(buf)
|
||||
tableDatas[v[index]] = v
|
||||
end
|
||||
elseif mode == "list" then
|
||||
tableDatas = {}
|
||||
for i = 1, buf:ReadSize() do
|
||||
local v = valueType._deserialize(buf)
|
||||
tinsert(tableDatas, v)
|
||||
end
|
||||
else
|
||||
assert(buf:ReadSize() == 1)
|
||||
tableDatas = valueType._deserialize(buf)
|
||||
end
|
||||
print(ttostring(tableDatas))
|
||||
tables[t.name] = tableDatas
|
||||
end
|
||||
end
|
||||
|
||||
---@param typeName string
|
||||
---@param key string
|
||||
function GetEnum(typeName, key)
|
||||
local def = enumDefs[typeName]
|
||||
return key and def[key] or def
|
||||
end
|
||||
|
||||
---@param typeName string
|
||||
---@param field string
|
||||
function GetConst(typeName, field)
|
||||
local def = constDefs[typeName]
|
||||
return field and def[field] or constDefs
|
||||
end
|
||||
|
||||
function GetData(tableName, key1, key2)
|
||||
local tableDatas = tables[tableName]
|
||||
if not key1 then
|
||||
return tableDatas
|
||||
end
|
||||
local value1 = tableDatas[key1]
|
||||
return key2 and value1[key2] or value1
|
||||
end
|
||||
|
||||
|
||||
|
||||
function C.Start()
|
||||
local cfgTypeDefs = require("Gen.schema").InitTypes(byteBufFuns)
|
||||
Load(cfgTypeDefs)
|
||||
end
|
||||
|
||||
|
||||
|
||||
return C
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 915f9500a82da6b43b71fa5a64864ee0
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f07c3f9ed91f3a459ca13dd539041bf
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
30
luban_examples/Projects/Lua_Unity_xlua_bin/Assets/Main.cs
Normal file
30
luban_examples/Projects/Lua_Unity_xlua_bin/Assets/Main.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using XLua;
|
||||
|
||||
public class Main : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
private LuaEnv _lua;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
_lua = new LuaEnv();
|
||||
|
||||
_lua.AddLoader(this.Loader);
|
||||
|
||||
_lua.DoString("(require 'Main').Start()");
|
||||
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
_lua.Dispose();
|
||||
}
|
||||
|
||||
private byte[] Loader(ref string luaModule)
|
||||
{
|
||||
return System.IO.File.ReadAllBytes(Application.dataPath + "/Lua/" + luaModule.Replace('.', '/') + ".lua");
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 77738bf2a0ca2654fa12b70763161bde
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1a66f79cb34d674caa0c0b0aa2c2c1b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4fb2cdac65a3be741a7cd71916dea60d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
@@ -0,0 +1,52 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 419a5f5be2476ee43afad369ced8a5a7
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Standalone: Linux64
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
Standalone: OSXUniversal
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
Standalone: Win
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: Win64
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
@@ -0,0 +1,52 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 977d8e48859dc19479dc2b5af538915c
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Standalone: Linux64
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
Standalone: OSXUniversal
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
Standalone: Win
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: None
|
||||
- first:
|
||||
Standalone: Win64
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 757bd977170654145961e692d39e36ce
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,314 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!29 &1
|
||||
OcclusionCullingSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 2
|
||||
m_OcclusionBakeSettings:
|
||||
smallestOccluder: 5
|
||||
smallestHole: 0.25
|
||||
backfaceThreshold: 100
|
||||
m_SceneGUID: 00000000000000000000000000000000
|
||||
m_OcclusionCullingData: {fileID: 0}
|
||||
--- !u!104 &2
|
||||
RenderSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 9
|
||||
m_Fog: 0
|
||||
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
|
||||
m_FogMode: 3
|
||||
m_FogDensity: 0.01
|
||||
m_LinearFogStart: 0
|
||||
m_LinearFogEnd: 300
|
||||
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
|
||||
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
|
||||
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
|
||||
m_AmbientIntensity: 1
|
||||
m_AmbientMode: 0
|
||||
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
|
||||
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_HaloStrength: 0.5
|
||||
m_FlareStrength: 1
|
||||
m_FlareFadeSpeed: 3
|
||||
m_HaloTexture: {fileID: 0}
|
||||
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
|
||||
m_DefaultReflectionMode: 0
|
||||
m_DefaultReflectionResolution: 128
|
||||
m_ReflectionBounces: 1
|
||||
m_ReflectionIntensity: 1
|
||||
m_CustomReflection: {fileID: 0}
|
||||
m_Sun: {fileID: 705507994}
|
||||
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
m_UseRadianceAmbientProbe: 0
|
||||
--- !u!157 &3
|
||||
LightmapSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 12
|
||||
m_GIWorkflowMode: 1
|
||||
m_GISettings:
|
||||
serializedVersion: 2
|
||||
m_BounceScale: 1
|
||||
m_IndirectOutputScale: 1
|
||||
m_AlbedoBoost: 1
|
||||
m_EnvironmentLightingMode: 0
|
||||
m_EnableBakedLightmaps: 1
|
||||
m_EnableRealtimeLightmaps: 0
|
||||
m_LightmapEditorSettings:
|
||||
serializedVersion: 12
|
||||
m_Resolution: 2
|
||||
m_BakeResolution: 40
|
||||
m_AtlasSize: 1024
|
||||
m_AO: 0
|
||||
m_AOMaxDistance: 1
|
||||
m_CompAOExponent: 1
|
||||
m_CompAOExponentDirect: 0
|
||||
m_ExtractAmbientOcclusion: 0
|
||||
m_Padding: 2
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_LightmapsBakeMode: 1
|
||||
m_TextureCompression: 1
|
||||
m_FinalGather: 0
|
||||
m_FinalGatherFiltering: 1
|
||||
m_FinalGatherRayCount: 256
|
||||
m_ReflectionCompression: 2
|
||||
m_MixedBakeMode: 2
|
||||
m_BakeBackend: 1
|
||||
m_PVRSampling: 1
|
||||
m_PVRDirectSampleCount: 32
|
||||
m_PVRSampleCount: 500
|
||||
m_PVRBounces: 2
|
||||
m_PVREnvironmentSampleCount: 500
|
||||
m_PVREnvironmentReferencePointCount: 2048
|
||||
m_PVRFilteringMode: 2
|
||||
m_PVRDenoiserTypeDirect: 0
|
||||
m_PVRDenoiserTypeIndirect: 0
|
||||
m_PVRDenoiserTypeAO: 0
|
||||
m_PVRFilterTypeDirect: 0
|
||||
m_PVRFilterTypeIndirect: 0
|
||||
m_PVRFilterTypeAO: 0
|
||||
m_PVREnvironmentMIS: 0
|
||||
m_PVRCulling: 1
|
||||
m_PVRFilteringGaussRadiusDirect: 1
|
||||
m_PVRFilteringGaussRadiusIndirect: 5
|
||||
m_PVRFilteringGaussRadiusAO: 2
|
||||
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
|
||||
m_PVRFilteringAtrousPositionSigmaIndirect: 2
|
||||
m_PVRFilteringAtrousPositionSigmaAO: 1
|
||||
m_ExportTrainingData: 0
|
||||
m_TrainingDataDestination: TrainingData
|
||||
m_LightProbeSampleCountMultiplier: 4
|
||||
m_LightingDataAsset: {fileID: 0}
|
||||
m_LightingSettings: {fileID: 4890085278179872738, guid: 12ee1d3a89573b84e82c16596315f50a,
|
||||
type: 2}
|
||||
--- !u!196 &4
|
||||
NavMeshSettings:
|
||||
serializedVersion: 2
|
||||
m_ObjectHideFlags: 0
|
||||
m_BuildSettings:
|
||||
serializedVersion: 2
|
||||
agentTypeID: 0
|
||||
agentRadius: 0.5
|
||||
agentHeight: 2
|
||||
agentSlope: 45
|
||||
agentClimb: 0.4
|
||||
ledgeDropHeight: 0
|
||||
maxJumpAcrossDistance: 0
|
||||
minRegionArea: 2
|
||||
manualCellSize: 0
|
||||
cellSize: 0.16666667
|
||||
manualTileSize: 0
|
||||
tileSize: 256
|
||||
accuratePlacement: 0
|
||||
maxJobWorkers: 0
|
||||
preserveTilesOutsideBounds: 0
|
||||
debug:
|
||||
m_Flags: 0
|
||||
m_NavMeshData: {fileID: 0}
|
||||
--- !u!1 &705507993
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 705507995}
|
||||
- component: {fileID: 705507994}
|
||||
m_Layer: 0
|
||||
m_Name: Directional Light
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!108 &705507994
|
||||
Light:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 705507993}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 10
|
||||
m_Type: 1
|
||||
m_Shape: 0
|
||||
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
|
||||
m_Intensity: 1
|
||||
m_Range: 10
|
||||
m_SpotAngle: 30
|
||||
m_InnerSpotAngle: 21.80208
|
||||
m_CookieSize: 10
|
||||
m_Shadows:
|
||||
m_Type: 2
|
||||
m_Resolution: -1
|
||||
m_CustomResolution: -1
|
||||
m_Strength: 1
|
||||
m_Bias: 0.05
|
||||
m_NormalBias: 0.4
|
||||
m_NearPlane: 0.2
|
||||
m_CullingMatrixOverride:
|
||||
e00: 1
|
||||
e01: 0
|
||||
e02: 0
|
||||
e03: 0
|
||||
e10: 0
|
||||
e11: 1
|
||||
e12: 0
|
||||
e13: 0
|
||||
e20: 0
|
||||
e21: 0
|
||||
e22: 1
|
||||
e23: 0
|
||||
e30: 0
|
||||
e31: 0
|
||||
e32: 0
|
||||
e33: 1
|
||||
m_UseCullingMatrixOverride: 0
|
||||
m_Cookie: {fileID: 0}
|
||||
m_DrawHalo: 0
|
||||
m_Flare: {fileID: 0}
|
||||
m_RenderMode: 0
|
||||
m_CullingMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_RenderingLayerMask: 1
|
||||
m_Lightmapping: 1
|
||||
m_LightShadowCasterMode: 0
|
||||
m_AreaSize: {x: 1, y: 1}
|
||||
m_BounceIntensity: 1
|
||||
m_ColorTemperature: 6570
|
||||
m_UseColorTemperature: 0
|
||||
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_UseBoundingSphereOverride: 0
|
||||
m_ShadowRadius: 0
|
||||
m_ShadowAngle: 0
|
||||
--- !u!4 &705507995
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 705507993}
|
||||
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
|
||||
m_LocalPosition: {x: 0, y: 3, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
|
||||
--- !u!1 &963194225
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 963194228}
|
||||
- component: {fileID: 963194227}
|
||||
- component: {fileID: 963194226}
|
||||
- component: {fileID: 963194229}
|
||||
m_Layer: 0
|
||||
m_Name: Main Camera
|
||||
m_TagString: MainCamera
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!81 &963194226
|
||||
AudioListener:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 963194225}
|
||||
m_Enabled: 1
|
||||
--- !u!20 &963194227
|
||||
Camera:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 963194225}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_ClearFlags: 1
|
||||
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
|
||||
m_projectionMatrixMode: 1
|
||||
m_GateFitMode: 2
|
||||
m_FOVAxisMode: 0
|
||||
m_SensorSize: {x: 36, y: 24}
|
||||
m_LensShift: {x: 0, y: 0}
|
||||
m_FocalLength: 50
|
||||
m_NormalizedViewPortRect:
|
||||
serializedVersion: 2
|
||||
x: 0
|
||||
y: 0
|
||||
width: 1
|
||||
height: 1
|
||||
near clip plane: 0.3
|
||||
far clip plane: 1000
|
||||
field of view: 60
|
||||
orthographic: 0
|
||||
orthographic size: 5
|
||||
m_Depth: -1
|
||||
m_CullingMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_RenderingPath: -1
|
||||
m_TargetTexture: {fileID: 0}
|
||||
m_TargetDisplay: 0
|
||||
m_TargetEye: 3
|
||||
m_HDR: 1
|
||||
m_AllowMSAA: 1
|
||||
m_AllowDynamicResolution: 0
|
||||
m_ForceIntoRT: 0
|
||||
m_OcclusionCulling: 1
|
||||
m_StereoConvergence: 10
|
||||
m_StereoSeparation: 0.022
|
||||
--- !u!4 &963194228
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 963194225}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 1, z: -10}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &963194229
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 963194225}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 77738bf2a0ca2654fa12b70763161bde, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf981549dcf6a8a48880a5daa16a65c6
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,63 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!850595691 &4890085278179872738
|
||||
LightingSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: SampleSceneSettings
|
||||
serializedVersion: 2
|
||||
m_GIWorkflowMode: 1
|
||||
m_EnableBakedLightmaps: 1
|
||||
m_EnableRealtimeLightmaps: 0
|
||||
m_RealtimeEnvironmentLighting: 1
|
||||
m_BounceScale: 1
|
||||
m_AlbedoBoost: 1
|
||||
m_IndirectOutputScale: 1
|
||||
m_UsingShadowmask: 1
|
||||
m_BakeBackend: 1
|
||||
m_LightmapMaxSize: 1024
|
||||
m_BakeResolution: 40
|
||||
m_Padding: 2
|
||||
m_TextureCompression: 1
|
||||
m_AO: 0
|
||||
m_AOMaxDistance: 1
|
||||
m_CompAOExponent: 1
|
||||
m_CompAOExponentDirect: 0
|
||||
m_ExtractAO: 0
|
||||
m_MixedBakeMode: 2
|
||||
m_LightmapsBakeMode: 1
|
||||
m_FilterMode: 1
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_ExportTrainingData: 0
|
||||
m_TrainingDataDestination: TrainingData
|
||||
m_RealtimeResolution: 2
|
||||
m_ForceWhiteAlbedo: 0
|
||||
m_ForceUpdates: 0
|
||||
m_FinalGather: 0
|
||||
m_FinalGatherRayCount: 256
|
||||
m_FinalGatherFiltering: 1
|
||||
m_PVRCulling: 1
|
||||
m_PVRSampling: 1
|
||||
m_PVRDirectSampleCount: 32
|
||||
m_PVRSampleCount: 500
|
||||
m_PVREnvironmentSampleCount: 500
|
||||
m_PVREnvironmentReferencePointCount: 2048
|
||||
m_LightProbeSampleCountMultiplier: 4
|
||||
m_PVRBounces: 2
|
||||
m_PVRRussianRouletteStartBounce: 2
|
||||
m_PVREnvironmentMIS: 0
|
||||
m_PVRFilteringMode: 2
|
||||
m_PVRDenoiserTypeDirect: 0
|
||||
m_PVRDenoiserTypeIndirect: 0
|
||||
m_PVRDenoiserTypeAO: 0
|
||||
m_PVRFilterTypeDirect: 0
|
||||
m_PVRFilterTypeIndirect: 0
|
||||
m_PVRFilterTypeAO: 0
|
||||
m_PVRFilteringGaussRadiusDirect: 1
|
||||
m_PVRFilteringGaussRadiusIndirect: 5
|
||||
m_PVRFilteringGaussRadiusAO: 2
|
||||
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
|
||||
m_PVRFilteringAtrousPositionSigmaIndirect: 2
|
||||
m_PVRFilteringAtrousPositionSigmaAO: 1
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 116b1a8a8ec55f34e8ef718f5a2a30e4
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e26ef49f16c28ae4c88b32a323da048e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,487 @@
|
||||
v2.1.15 2020年6月24日
|
||||
新增特性
|
||||
1、生成代码过滤器
|
||||
2、优化反射查找delegate匹配bridge的性能
|
||||
3、unity 2019.2以上版本手机版本注入不了的问题
|
||||
|
||||
变更
|
||||
|
||||
bug修复
|
||||
1、反射查找同名delegate桥接在不生成代码的时候表现不一致
|
||||
2、嵌套struct标注为PackAsTable时生成代码报错
|
||||
3、反射wrap代码加入栈空间检查
|
||||
4、如果枚举定义了很多个值(几千个),会触发unity在android下的一个bug:函数体很大而且有很多分支,执行该函数会crash
|
||||
5、chunkname和脚本文件名不一致的问题
|
||||
6、最小生成模式枚举生成代码报错
|
||||
7、当采用反射方式注册枚举值时,如果一个枚举有多个相同的值,比如A,B都是1,那么在lua里头访问B将会为空
|
||||
8、sbyte[]在.net 4下push到lua变成字符串的问题
|
||||
9、泛型导致生成代码失败的问题
|
||||
10、非Assembly-CSharp程序集注入时,out参数处理有误
|
||||
11、内嵌类通过xlua.private_accessible设置私有访问可能失败的问题
|
||||
12、cecil插入指令后,并未自动更新offset,某种情况下会导致计算偏移量错误
|
||||
|
||||
|
||||
v2.1.14 2019年2月27日
|
||||
新增特性
|
||||
1、新增nintento switch的支持
|
||||
2、unity 2018兼容
|
||||
3、android arm64支持
|
||||
4、原生库的visual studio 2017编译支持
|
||||
5、增加“XLua/Generate Minimize Code”菜单
|
||||
6、防止有的工程有非法的dll导致生成代码中断
|
||||
7、更高效的lua_pushstring(需要通过NATIVE_LUA_PUSHSTRING开启)
|
||||
|
||||
变更
|
||||
1、window库默认编译器改为visual studio 2017
|
||||
|
||||
bug修复
|
||||
1、修正枚举类型如果只加GCOptimize不加LuaCallCSharp会crash的问题
|
||||
2、示例配置加入对Edtitor类的过滤
|
||||
3、UWP兼容修复
|
||||
4、接口继承引入的同签名方法实现
|
||||
5、未生成代码,extension方法行为不一致
|
||||
6、修复Nullable类型参数,如果最后一个参数是nil,会导致其他参数全是nil的问题
|
||||
|
||||
|
||||
v2.1.13 2018年12月5日
|
||||
新增特性
|
||||
1、新增AdaptByDelegate注入模式;
|
||||
2、新增xlua.get_generic_method,用于调用泛型函数;
|
||||
3、支持类似CS.System.Collections.Generic.List(CS.System.Int32)的泛型写法;
|
||||
4、注入新选项:忽略编译器自动生成代码,以及不生成base代理;
|
||||
5、针对lua编程以及热补丁,均添加直接可用的自动化配置样例;
|
||||
6、新增luajit的gc64支持;
|
||||
7、加入兼容字节码(一份字节码支持32位和64位系统)的支持;
|
||||
8、内置新lua内存泄漏检测工具;
|
||||
9、delegate桥接动态实例化:delegate是4个参数以内,参数均引用类型,无返回值或者返回引用类型,不用配置CSharpCallLua也能调用lua函数;
|
||||
10、提供util.print_func_ref_by_csharp函数,用于查看当前被C#引用的lua函数;
|
||||
11、支持无CS全局变量的工作方式;
|
||||
|
||||
|
||||
变更
|
||||
1、虚拟机升级:lua5.3.4 -> lua5.3.5,luajit2.1b2 -> luajit2.1b3;
|
||||
2、delegate bridge代码段占用优化;
|
||||
3、改为PostProcessBuild事件检查是否生成代码;
|
||||
4、适配xcode 10:osx平台不再支持32bit版本构建;
|
||||
5、名字空间、类名拼写错误时,对静态成员的设置会报错;
|
||||
6、防止CS全局table被删除导致xlua工作异常;
|
||||
7、Windows下构建lib,若使用vs 2015参数执行cmake失败,则继续尝试使用vs 2017;
|
||||
8、编辑器下不生成代码时,也检查Blacklist,维持和运行时一致;
|
||||
|
||||
bug修复
|
||||
1、泛型的数组生成代码报错;
|
||||
2、防止对TypeExtensions配置了LuaCallCSharp后,lua里头IsValueType之类的判断永真;
|
||||
3、生成代码过滤掉含指针的函数和字段;
|
||||
4、适应索引器属性名不是Item的情况;
|
||||
5、解决attribute初始化异常会导致生成代码,注入终止的问题;
|
||||
6、精简模式下空Enum生成代码错误;
|
||||
7、通过把初始化函数分割成小函数,规避unity在android下执行大函数crash的bug;
|
||||
8、Assignable处理obj为null情况;
|
||||
9、内嵌类不Obsolete,但外层类Obsolete的生成代码报错
|
||||
10、解决inline注入方式下,如果lua逻辑跑异常,看不到异常信息的问题;
|
||||
11、修复xlua.private_accessible访问后,同名public的方法无法访问的Bug;
|
||||
12、[Out]修饰的参数不应该生成out关键字;
|
||||
13、通过反射查找合适的适配器时,有可能访问到非适配器函数;
|
||||
14、精简模式导出代码无get_Item、set_Item;
|
||||
15、IntKey方式下不自动xlua.private_accessible的问题;
|
||||
|
||||
|
||||
v2.1.12 2018年7月9日
|
||||
新增特性
|
||||
1、Nullable的支持
|
||||
2、支持Assembly-CSharp之外的dll注入(beta)
|
||||
3、执行xlua.hotfix,会自动让该类private能访问
|
||||
4、xlua.private_accessible优化:1、会把基类的也设置能私有访问;2、延迟到第一次访问类才私有化
|
||||
5、新增xlua.util.state,可为一个c#对象新增状态
|
||||
6、this[string field]或者this[object field]操作符重载新增get_Item和set_Item调用
|
||||
7、正在编译时注入打印error信息
|
||||
8、interface配置到CSharpCallLua时的事件跟索引映射的自动实现
|
||||
9、unity5.5以上去掉WARNING: The runtime version supported by this application is unavailable打印
|
||||
|
||||
变更
|
||||
1、去除Stateful方式(因为xlua.util.state已经可以达成类似的效果)
|
||||
2、废弃掉内嵌模式模式
|
||||
|
||||
bug修复
|
||||
1、生成代码局部变量加下划线,防止符号冲突
|
||||
2、如果类没放到Hotfix列表,不生成base调用代理
|
||||
3、代码重构,可读性优化
|
||||
4、解决带params byte[]可能会导致生成代码编译错误的问题
|
||||
5、解决类含有private event的时候,无法xlua.private_accessible的问题
|
||||
6、构造函数注入,如果branch外紧跟Ret指令,注入逻辑应该在branch以及Ret之间
|
||||
7、构造函数注入,如果注入指令后导致跳转范围大于一个字节,应修改为长跳转
|
||||
8、解决一个delegate如果不是某个类的内嵌类型时,CS.namespace.classname为空的问题
|
||||
9、防止Editor下的Util类名字冲突
|
||||
10、泛型override有异常,先过滤掉
|
||||
11、解决空enum导致生成代码编译错误
|
||||
12、解决uwp平台下il2cpp方式打包无法访问任何类的问题
|
||||
13、hotfix一个私有类型的params参数的函数,导致生成代码编译错误、注入失败的问题
|
||||
14、如果两个LuaBase指向的是同一个Lua对象,GetHashCode应该返回的是同一个值
|
||||
15、[Out]标记参数生成代码编译失败
|
||||
16、交错数组+多维数组的复合,生成代码报错的问题
|
||||
|
||||
v2.1.11 2018年3月20日
|
||||
新增特性
|
||||
1、xlua.private_accessible支持私有内嵌类型
|
||||
2、添加xlua.release,用于主动解除lua对c#某对象的引用
|
||||
3、支持内嵌委托的显示构造
|
||||
4、需要传class的地方(比如xlua.private_accessible),支持传C#的Type对象
|
||||
5、支持用pairs遍历IEnumerable对象
|
||||
6、热补丁场景下,支持override函数调用被override函数(对应c# base关键字)
|
||||
|
||||
变更
|
||||
1、简化property的反射访问,简化后有更好的兼容性;
|
||||
|
||||
bug修复
|
||||
1、ios 11兼容(去除system调用)
|
||||
2、实现了interface的struct不走gc优化代码的问题
|
||||
3、emit特性的.net兼容性
|
||||
4、emit对于ulong的const值处理不当
|
||||
5、interface桥接代码,interface继承时,父interface和子interface有同名不同类型属性时的生成代码报错
|
||||
6、多虚拟机下,不断创建和销毁协程时,可能出现协程指针重复
|
||||
7、当参数为泛型类型时,如ICollectio时,不应该生成代码
|
||||
|
||||
v2.1.10 2017年9月18日
|
||||
新增特性
|
||||
1、新增DoNotGen配置,支持一个类型部分函数用反射,部分用生成;
|
||||
2、新增wrapper的emit;
|
||||
3、webgl支持;
|
||||
4、lua实现interface支持interface继承;
|
||||
5、window下支持android编译(由xdestiny110提供);
|
||||
6、打包时,如果没执行过“Generate Code”将报错;
|
||||
|
||||
变更
|
||||
1、 async_to_sync的改为resume错误时报错;
|
||||
2、il2cpp下,暂时去掉泛型的反射调用;
|
||||
3、升级到lua5.3.4并合入2017-9-1为止所有官方patch;
|
||||
|
||||
bug修复
|
||||
1、C#仅声明delegate和MulticastDelegate,通过反射创建lua function映射时crash;
|
||||
2、解决一些古老版本window(比如xp)的dll兼容问题;
|
||||
|
||||
v2.1.9 2017年8月10日
|
||||
新增特性
|
||||
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侧完成;
|
||||
5、反射下扩展方法的支持;
|
||||
6、lua53版本支持位操作符重载:C#侧的位操作符重载对应到lua的位操作符重载;enum全部加上&和|位操作符;
|
||||
|
||||
工程优化
|
||||
1、加入travis持续集成;
|
||||
|
||||
变更
|
||||
1、LuaCallCSharp自动去除匿名类型;
|
||||
2、THREAD_SAFT改为THREAD_SAFE;
|
||||
3、GenFlag.GCOptimize标记为过时;
|
||||
4、删除过时的GenConfig配置方式;
|
||||
|
||||
bug修复
|
||||
1、window phone下一些系统api是禁用的,源码中去掉;
|
||||
2、泛型约束是struct的时候,生成代码失败;
|
||||
3、unity2017 .net 4.6,枚举生成代码报错;
|
||||
|
||||
v2.1.8 2017年6月27日
|
||||
新增特性
|
||||
1、Hotfix标签添加几个订制参数:ValueTypeBoxing、IgnoreProperty、IgnoreNotPublic、Inline、IntKey
|
||||
2、Hotfix代码注入优化,减少text段占用;
|
||||
3、Hotfix配置支持放Editor目录,可以减少text段占用;
|
||||
4、支持以指定类型传递object参数;
|
||||
5、反射调用Obsolete方法在Editor下打印warning;
|
||||
|
||||
变更
|
||||
|
||||
bug修复
|
||||
1、pinvoke独立设置的In,Out属性可能导致生成代码失败;
|
||||
2、如果业务在全局名字空间有和xLua名字空间的同名类,生成代码编译失败;
|
||||
|
||||
v2.1.7 2017年5月17日
|
||||
新增特性
|
||||
1、支持发布UWP(含HoloLens,Xbox one,Win10 Mobile、Win10 PC)应用;
|
||||
2、支持对lua源代码ras+sha1签名;
|
||||
3、如果没安装Tools提示“please install the Tools”;
|
||||
4、linxu版本的支持;
|
||||
5、支持bitcode打包;
|
||||
6、对所有struct新增无参数构造函数;
|
||||
7、delegate的参数名改为p0到pn,防止hotfix时业务代码变量和生成代码冲突;
|
||||
8、支持对成员名为C#关键字的情况;
|
||||
9、新增util.loadpackage,和require类似,通过searcher加载文件,不同的是,它不执行,而且也不会cache到package.loaded;
|
||||
10、优化模版引擎大文件的生成性能;
|
||||
11、新增不需要生成代码的注入方式;
|
||||
12、支持构造函数参数带ref和out修饰符;
|
||||
13、构造函数也支持黑名单排除;
|
||||
|
||||
变更
|
||||
1、this[object field]操作符重载;
|
||||
2、反射的数据转换规则改成和生成代码一致;
|
||||
3、忽略掉匿名类及匿名函数的注入;
|
||||
|
||||
bug修复
|
||||
1、规避Unity的bug:List<CustomType>,CustomType是当前执行程序集的类型,这在.Net是不需要指明程序集就可以通过Type.GetType得到,但Unity下不行。
|
||||
2、解决反射下,可变参数不提供时,传null的问题;
|
||||
3、继承了另外一个程序集的类型,使用了protected类型会导致注入失败;
|
||||
4、luajit去掉dlopen和dlsym的调用;
|
||||
5、解决通用版本的生成代码工具找不到模版的问题;
|
||||
6、修复通用版本反射导入泛化类型的问题;
|
||||
7、反射调用含delegate参数的的api,会因为缓存而导致调用LuaEnv.Dispose失败;
|
||||
8、兼容老版本的C编译器,声明要放开头;
|
||||
9、生成代码对hotfix的检测算法和注入工具不一致导致的注入失败;
|
||||
10、注入的nested类型是public,但其的外层类型非public,生成代码报错;
|
||||
11、析构函数只判断名字可能出现误判;
|
||||
12、构造函数是非public的,可能会导致找不到适配delegate而注入失败;
|
||||
13、修正Extension method会在所有子类都生成代码的bug(2.1.6泛化特性引入);
|
||||
14、构造函数重载,只有一个能hotfix成功;
|
||||
15、规避一个可能是il2cpp的bug(unity5.4):字符串参数默认值是"",ios下在反射的default value也是Reflection.Missing;
|
||||
16、将一个table传到List<>,取了最后一个参数,而不是那个table的长度;
|
||||
17、ldarg指令在这种场景下il2cpp转换时会出现异常:1、采用模版注入;2、从4到255间有一个输出参数;改为兼容性更好的ldarg.s;
|
||||
18、解决配置了System.Delegate到CSCallLua,执行生成代码会编辑器会crash的问题;
|
||||
19、扩展函数可能和原来的函数同名,反射实现并未考虑到这种情况;
|
||||
20、通用版本的可变参数delegate调用异常;
|
||||
21、unity4规避lua53冲突的方式改为返回null更合适,异常方式会导致IsNull无法正常工作;
|
||||
22、lua_tostring解码失败改为UTF8解码;
|
||||
|
||||
v2.1.6 2017年3月1日
|
||||
新增特性
|
||||
1、带约束的泛型支持(by forsakenyang);
|
||||
2、非Unity的.net环境支持;
|
||||
3、代码注入支持小工具方式,该方式不用拷贝cecil库,可以解决拷错cecil库版本或者和Unity,VS插件冲突的问题;
|
||||
4、Hotfix配置支持字段和属性
|
||||
5、更方便的Unity协程hotfix
|
||||
6、在hotfix触发事件;
|
||||
7、LuaTable添加ForEach方法以及Length属性;
|
||||
8、cmake生成项目优化:保留源文件目录结构;
|
||||
9、对已经Dispose的LuaEnv的访问做保护;Dispose时检查callback是否已经都释放,没释放的话报错;
|
||||
10、支持释放Hotfix回调;
|
||||
|
||||
变更
|
||||
1、构造函数改为执行原有逻辑后调用lua;
|
||||
2、this[string field]操作符重载会影响到继承调用,去掉该特性的支持;
|
||||
3、编辑器下的代码注入改为手动方式;
|
||||
|
||||
bug修复
|
||||
1、防止定义了同时定义get_xx方法以及xx属性的生成代码的重名。
|
||||
2、struct注入代码无效;
|
||||
3、Utils加名字空间,防止和业务冲突;
|
||||
4、返回定长多维数组的delegate,生成代码可能会冲突;
|
||||
5、interface,以及编辑器下不生成代码情况下,对可变参数的展开;
|
||||
6、il2cpp下,如果不生成代码,会报ManifestModule不支持;
|
||||
7、规避Unity4的bug:访问一个已经被Distroy的UnityEngine.Object,编辑器下会崩溃,这个问题在Unity5,或者luajit版本都不会出现;
|
||||
8、修改上个版本引入的问题:xlua_setglobal会漏一个值在栈上,这会导致一些32位应用不稳定;
|
||||
9、当delegate参数只有ref和out的区别的话,报重载冲突;
|
||||
|
||||
v2.1.5 2017年1月13日
|
||||
|
||||
新增特性
|
||||
1、全平台热补丁;
|
||||
2、新增线程安全模式,可通过THREAD_SAFT宏打开;
|
||||
3、新增更简便的配置方式,具体参见XLua\Doc下《XLua的配置.doc》;
|
||||
4、多虚拟机实例时的自动Dispose;
|
||||
5、内存优化:减少匿名闭包到delegate映射的内存占用;减少LuaFunction以及LuaTable内存占用;减少lua table映射C#interface的gc;
|
||||
6、生成代码速度优化;
|
||||
7、支持直接在lua侧clone C#结构体;
|
||||
8、LuaFunction新增无gc调用api;
|
||||
|
||||
变更
|
||||
1、delegate必须都加[CSharpCallLua]才支持C#到lua的回调(以前参数和返回值都相同的delegate只要其中一个加了就可以);
|
||||
2、加回string/number到枚举的自动转换;
|
||||
|
||||
bug修复
|
||||
1、枚举不生成代码时,第一次使用会产生两个不同的userdata;
|
||||
2、数组和System.Type的相互引用导致System.Type生成代码无法加载;
|
||||
3、更安全的异常处理,封装lua_setglobal,lua_getglobal的异常,C#回调保证所有C#异常都catch并转换到成lua error。
|
||||
|
||||
|
||||
v2.1.4 2016年11月29日
|
||||
新增特性
|
||||
1、加了ReflectionUse会自动生成到link.xml,可以防止il2cpp下因stripping导致的反射不可用;
|
||||
2、开放生成引擎,可二次开发自己生成插件,生成所需的代码或配置;
|
||||
3、GetInPath和SetInPath无C# gc优化;
|
||||
4、一个lua table自动转换为带GCOptimize标签的复杂类型以及该复杂类型的一维数组不使用反射,如果这复杂类型是纯值类型,无c# gc;
|
||||
|
||||
变更
|
||||
1、基于一致性以及性能的考虑,不支持数字和字符串到枚举的静默转换,须主动调用起类下的__CastFrom;
|
||||
2、名字空间从LuaInterface改为XLua;
|
||||
3、LuaTable的几个可能导致gc的api标注为Obsolete;
|
||||
4、在不指明返回类型的情况下,如果一个number是整数会优先转换成整数;
|
||||
|
||||
bug修复
|
||||
1、含能隐式转换int,long,decimal的类型传到lua变成decimal;
|
||||
2、反射的重载判断,如果可变参数的位置上是一个不匹配的参数,也会判断为匹配成功;
|
||||
3、可变参数+重载的话,可变部分不传会报无效参数;
|
||||
4、加了LuaCallCSharp的Extension method,在Editor下不生成代码不可用;
|
||||
|
||||
v2.1.3 2016年11月09日
|
||||
新增特性
|
||||
1、LuaTable新增Get<TKey, TValue>和Set<TKey, TValue>接口,table操作支持值类型无gc;
|
||||
2、支持decimal,不丢失精度而且传递到lua无gc;
|
||||
3、增加LuaEnv.LoadString<T>接口,用于指定返回的delegate类型;
|
||||
4、例子刷新:新增Helloworld,无GC调用,Lua面向对象,协程例子;
|
||||
5、enum优化:传递到lua无gc,从int或者string到枚举转换无gc;
|
||||
6、event的+/-优化:性能提升一倍,而且无gc;
|
||||
7、生成代码简化;
|
||||
|
||||
变更
|
||||
1、uint在lua53映射到lua_Integer;
|
||||
2、StreamingAssets加载改为优先级最低;
|
||||
|
||||
bug修复
|
||||
1、生成代码下,如果LuaTable或者LuaFunction参数为null会抛异常;
|
||||
2、lua5.3下,浮点到枚举的静默转换失败;
|
||||
3、反射下struct类型参数带默认值抛异常;
|
||||
4、lua53下Length返回浮点;
|
||||
|
||||
v2.1.2 2016年10月08日
|
||||
新增特性
|
||||
1、支持lua5.3,进而支持苹果bitcode,原生64位整数,位运算,utf8等特性;
|
||||
2、CMake编译,更方便加入第三方插件
|
||||
3、数组性能优化,包括访问性能以及gc
|
||||
4、C#调用lua函数减少一次lua gc;
|
||||
5、优化启动时间;
|
||||
6、减少类型加载的gc;
|
||||
7、优化ObjectPool的内存占用;
|
||||
8、优化小字符串传入lua的gc;
|
||||
9、LuaTable添加Cast接口,用于LuaTable到其它类型的转换,比如interface;
|
||||
10、LuaFunction添加Cast接口,用于LuaFunction到delegate的转换;
|
||||
|
||||
变更
|
||||
1、lua内部只有带符号的64整数类型,并增加无符号数库
|
||||
2、如果不想对Extension Method生成代码,又希望在反射下用,需要添加ReflectionUse;
|
||||
|
||||
bug修复
|
||||
1、对ObjectPool已经Destroy的UnityEngine.Object的引用自动解除功能的内存泄漏问题;
|
||||
2、规避某些版本(已知是5.3.3)的Unity的bug导致的内存泄漏问题;
|
||||
3、LuaTable或者LuaFunction做返回值的delegate生成代码可能报错;
|
||||
|
||||
v2.1.1 2016年08月29日
|
||||
新增特性
|
||||
1、支持编辑器下不用生成代码能运行;
|
||||
2、新增IntPtr的支持
|
||||
3、增加对ObjectPool已经Destroy的UnityEngine.Object的引用自动解除;
|
||||
4、在LuaEnv添加对lua_gc一些封装;
|
||||
|
||||
bug修复
|
||||
1、生成代码传送一个LuaFunction、LuaTable到lua和反射版本不一致,生成代码传送过去是一个C#对象,而反射是Lua函数、table对象,反射的处理更合适;
|
||||
2、修复同名的静态以及成员方法冲突的问题;
|
||||
3、修复对interface生成CSharpCallLua代码时,interface含indexer时的报错;
|
||||
4、修复Editor在运行后会new一个xlua实例的bug;
|
||||
5、修复通过生成代码调用同时含可变参数和默认值的函数,如果不传参数,将会出错的bug;
|
||||
6、修复调试时,找不到socket库的bug;
|
||||
|
||||
|
||||
变更
|
||||
1、反射不做重载方法顺序调整,顺序改为固定且生成代码保持一致;
|
||||
2、i64加上fade_id,参数传递时更安全;
|
||||
3、重新加入tdr的from_file的支持;
|
||||
|
||||
v2.1.0 2016年08月08日
|
||||
新增特性
|
||||
1、满足条件struct传递到lua无gc,struct需要满足什么条件才能被优化呢?
|
||||
a. struct允许嵌套其它struct,但它以及它嵌套的struct只能包含这几种基本类型:byte、sbyte、short、ushort、int、uint、long、ulong、float、double;
|
||||
b. struct本身以及使用到该struct的地方需要加LuaCallCSharp,并且加了GCOptimize设置;
|
||||
2、全新实现的反射机制,更容易和生成代码配合使用
|
||||
a. 支持extension methods,Enum.__CastFrom;
|
||||
b. ios下支持反射使用event;
|
||||
c. 对类型映射、可变参数调用调整为和生成代码一致;
|
||||
d. 性能更好,gc更少;
|
||||
3、生成代码菜单简化,并增加“Generate Minimum”选项;
|
||||
4、支持生成代码配置文件放Editor目录;
|
||||
|
||||
变更
|
||||
1、luajit统一升级成2.1.0b2;
|
||||
2、luasocket库改为按需加载;
|
||||
3、重载的string,byte[]参数检查允许为nil;
|
||||
4、子类访问不触发父类加载;
|
||||
5、struct的ref参数的修改会修改lua测该参数的值;
|
||||
6、生成代码加载改为静态(原来是反射);
|
||||
7、菜单改为更简洁;
|
||||
8、tdr改为默认不加载;
|
||||
9、StreamingAssets加载lua改为废弃特性;
|
||||
|
||||
bug修复
|
||||
1、参数或者返回值是泛型类的数组,或者是二维数组,生成代码报编译错误;
|
||||
2、抽象类生成代码报编译错误;
|
||||
3、消除Clear生成代码的warning;
|
||||
4、profiler、i64库不支持多实例;
|
||||
|
||||
v2.0.5 2016年05月18日
|
||||
新增特性
|
||||
1、util.async_to_sync,可以更好的利用lua的协程实现同步编程、异步执行;或者异步等待www等;
|
||||
2、生成代码的规范度调整,消除一些工具的告警;
|
||||
bug修复
|
||||
1、解决在lua gc移除weak table和调用__gc的时间窗内push同一对象,会生成指向同一C#对象的不同userdata的问题;
|
||||
2、上版本的的lua内存工具并未打包;
|
||||
3、修正嵌套类型不能生成代码的问题;
|
||||
|
||||
v2.0.4 2016年05月04日
|
||||
新增特性
|
||||
1、新增函数调用时长报告功能;
|
||||
2、新增lua内存泄漏定位工具;
|
||||
3、lua测加入对64位无符号数的支持;
|
||||
变更
|
||||
1、支持多种delegate绑定到一个clousre。调整之前一个clousre只能对应一种delegate;
|
||||
bug修复
|
||||
1、tdr处理长度为1的数组的错误(本来解包应该是{[1] = {a = 1}}的,却是{{a=1}});
|
||||
2、tdr数值处理错误(int的-1会解成一个很大的正数)
|
||||
|
||||
v2.0.3 2016年04月13日
|
||||
新功能
|
||||
1、添加“Advanced Gen”功能,用户可以自定义生成代码的范围;
|
||||
2、支持对库生成Static pusher;
|
||||
变更
|
||||
1、LuaTable以及InterfaceBirdage改为触发metatable;
|
||||
2、Extension Methods不自动加到被扩展类,需要加入生成列表;
|
||||
3、移除特殊ValueType优化;
|
||||
bug修复
|
||||
1、Extension Methods为私有时,生成代码语法错误;
|
||||
2、重载函数含ulong时,生成代码语法错误;
|
||||
3、反射调用时的默认值处理错误;
|
||||
4、C#向lua传中文字符的长度处理错误;
|
||||
|
||||
v2.0.2 2016年04月06日
|
||||
变更
|
||||
1、库的生成代码配置支持多份,方便项目的模块化;
|
||||
2、enum的生成代码合并到一个文件里头;
|
||||
3、优化异常处理;
|
||||
4、发布包把库和教程、例子分离,更干净;
|
||||
5、小bug修改;
|
||||
|
||||
升级指引
|
||||
由于文件有点变动,直接覆盖原有lib会报错,需要:
|
||||
1、删除原来的XLua目录;
|
||||
2、解压xlua_v2.0.2.zip到Assets下;
|
||||
3、重新执行代码生成;
|
||||
|
||||
v2.0.1 2016年03月24日
|
||||
1、支持C# 的extension methods;
|
||||
2、lua调试方面的支持;
|
||||
3、android下require一个不存在的lua文件可能成功的bug;
|
||||
4、TDR 4 Lua库的更新;
|
||||
5、多机型的兼容性测试;
|
||||
|
||||
v2.0.0 2016年03月08日
|
||||
1、性能优化,性能对比报告请看主页;
|
||||
2、加入官方lua版本的tdr;
|
||||
3、支持64位整数;
|
||||
4、修正lua中对C#异常pcall引发的不稳定;
|
||||
5、易用性的优化;
|
||||
6、其它一些bug的修改。
|
||||
|
||||
1.0.2 2015年12月09日
|
||||
1、解决新版本(已知5.2版本)下,streamAssetsPath不允许在构造函数访问导致的bug;
|
||||
2、新增windows x64版本的支持;
|
||||
3、对web版本才用到的代码加入条件编译,减少对手机版发布包的影响;
|
||||
4、生成代码文件名去掉“+”号;
|
||||
5、删除4.6的生成代码,以免在新版本报引用过时api的错;
|
||||
|
||||
v1.0.1 2015年11月30日
|
||||
1、支持pcall捕捉C#异常;
|
||||
2、新增cast方法,支持这种场景:实现类是internal声明,只提供interface;
|
||||
3、解决interface下如果有event,生成代码编译报错的bug;
|
||||
4、解决interface下有Obsolete的方法,字段,生成代码编译报错的bug;
|
||||
5、解决含private的默认geter/setter生成代码编译报错的bug;
|
||||
6、修正类在全局空间下生成代码不可用的bug;
|
||||
7、修正bridge代码返回值处理错误。
|
||||
|
||||
v1.0.0 2015年03月30日
|
||||
第一个版本
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fb30792e31e15fc45b797304aebbd657
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e1fddbe23619b24a8573f801b9b9ad9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,307 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making xLua available.
|
||||
* Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
* http://opensource.org/licenses/MIT
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using XLua;
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
|
||||
//配置的详细介绍请看Doc下《XLua的配置.doc》
|
||||
public static class ExampleConfig
|
||||
{
|
||||
/***************如果你全lua编程,可以参考这份自动化配置***************/
|
||||
//--------------begin 纯lua编程配置参考----------------------------
|
||||
//static List<string> exclude = new List<string> {
|
||||
// "HideInInspector", "ExecuteInEditMode",
|
||||
// "AddComponentMenu", "ContextMenu",
|
||||
// "RequireComponent", "DisallowMultipleComponent",
|
||||
// "SerializeField", "AssemblyIsEditorAssembly",
|
||||
// "Attribute", "Types",
|
||||
// "UnitySurrogateSelector", "TrackedReference",
|
||||
// "TypeInferenceRules", "FFTWindow",
|
||||
// "RPC", "Network", "MasterServer",
|
||||
// "BitStream", "HostData",
|
||||
// "ConnectionTesterStatus", "GUI", "EventType",
|
||||
// "EventModifiers", "FontStyle", "TextAlignment",
|
||||
// "TextEditor", "TextEditorDblClickSnapping",
|
||||
// "TextGenerator", "TextClipping", "Gizmos",
|
||||
// "ADBannerView", "ADInterstitialAd",
|
||||
// "Android", "Tizen", "jvalue",
|
||||
// "iPhone", "iOS", "Windows", "CalendarIdentifier",
|
||||
// "CalendarUnit", "CalendarUnit",
|
||||
// "ClusterInput", "FullScreenMovieControlMode",
|
||||
// "FullScreenMovieScalingMode", "Handheld",
|
||||
// "LocalNotification", "NotificationServices",
|
||||
// "RemoteNotificationType", "RemoteNotification",
|
||||
// "SamsungTV", "TextureCompressionQuality",
|
||||
// "TouchScreenKeyboardType", "TouchScreenKeyboard",
|
||||
// "MovieTexture", "UnityEngineInternal",
|
||||
// "Terrain", "Tree", "SplatPrototype",
|
||||
// "DetailPrototype", "DetailRenderMode",
|
||||
// "MeshSubsetCombineUtility", "AOT", "Social", "Enumerator",
|
||||
// "SendMouseEvents", "Cursor", "Flash", "ActionScript",
|
||||
// "OnRequestRebuild", "Ping",
|
||||
// "ShaderVariantCollection", "SimpleJson.Reflection",
|
||||
// "CoroutineTween", "GraphicRebuildTracker",
|
||||
// "Advertisements", "UnityEditor", "WSA",
|
||||
// "EventProvider", "Apple",
|
||||
// "ClusterInput", "Motion",
|
||||
// "UnityEngine.UI.ReflectionMethodsCache", "NativeLeakDetection",
|
||||
// "NativeLeakDetectionMode", "WWWAudioExtensions", "UnityEngine.Experimental",
|
||||
//};
|
||||
|
||||
//static bool isExcluded(Type type)
|
||||
//{
|
||||
// var fullName = type.FullName;
|
||||
// for (int i = 0; i < exclude.Count; i++)
|
||||
// {
|
||||
// if (fullName.Contains(exclude[i]))
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
//}
|
||||
|
||||
//[LuaCallCSharp]
|
||||
//public static IEnumerable<Type> LuaCallCSharp
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// List<string> namespaces = new List<string>() // 在这里添加名字空间
|
||||
// {
|
||||
// "UnityEngine",
|
||||
// "UnityEngine.UI"
|
||||
// };
|
||||
// var unityTypes = (from assembly in AppDomain.CurrentDomain.GetAssemblies()
|
||||
// where !(assembly.ManifestModule is System.Reflection.Emit.ModuleBuilder)
|
||||
// from type in assembly.GetExportedTypes()
|
||||
// where type.Namespace != null && namespaces.Contains(type.Namespace) && !isExcluded(type)
|
||||
// && type.BaseType != typeof(MulticastDelegate) && !type.IsInterface && !type.IsEnum
|
||||
// select type);
|
||||
|
||||
// string[] customAssemblys = new string[] {
|
||||
// "Assembly-CSharp",
|
||||
// };
|
||||
// var customTypes = (from assembly in customAssemblys.Select(s => Assembly.Load(s))
|
||||
// from type in assembly.GetExportedTypes()
|
||||
// where type.Namespace == null || !type.Namespace.StartsWith("XLua")
|
||||
// && type.BaseType != typeof(MulticastDelegate) && !type.IsInterface && !type.IsEnum
|
||||
// select type);
|
||||
// return unityTypes.Concat(customTypes);
|
||||
// }
|
||||
//}
|
||||
|
||||
////自动把LuaCallCSharp涉及到的delegate加到CSharpCallLua列表,后续可以直接用lua函数做callback
|
||||
//[CSharpCallLua]
|
||||
//public static List<Type> CSharpCallLua
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// var lua_call_csharp = LuaCallCSharp;
|
||||
// var delegate_types = new List<Type>();
|
||||
// var flag = BindingFlags.Public | BindingFlags.Instance
|
||||
// | BindingFlags.Static | BindingFlags.IgnoreCase | BindingFlags.DeclaredOnly;
|
||||
// foreach (var field in (from type in lua_call_csharp select type).SelectMany(type => type.GetFields(flag)))
|
||||
// {
|
||||
// if (typeof(Delegate).IsAssignableFrom(field.FieldType))
|
||||
// {
|
||||
// delegate_types.Add(field.FieldType);
|
||||
// }
|
||||
// }
|
||||
|
||||
// foreach (var method in (from type in lua_call_csharp select type).SelectMany(type => type.GetMethods(flag)))
|
||||
// {
|
||||
// if (typeof(Delegate).IsAssignableFrom(method.ReturnType))
|
||||
// {
|
||||
// delegate_types.Add(method.ReturnType);
|
||||
// }
|
||||
// foreach (var param in method.GetParameters())
|
||||
// {
|
||||
// var paramType = param.ParameterType.IsByRef ? param.ParameterType.GetElementType() : param.ParameterType;
|
||||
// if (typeof(Delegate).IsAssignableFrom(paramType))
|
||||
// {
|
||||
// delegate_types.Add(paramType);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return delegate_types.Where(t => t.BaseType == typeof(MulticastDelegate) && !hasGenericParameter(t) && !delegateHasEditorRef(t)).Distinct().ToList();
|
||||
// }
|
||||
//}
|
||||
//--------------end 纯lua编程配置参考----------------------------
|
||||
|
||||
/***************热补丁可以参考这份自动化配置***************/
|
||||
//[Hotfix]
|
||||
//static IEnumerable<Type> HotfixInject
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// return (from type in Assembly.Load("Assembly-CSharp").GetTypes()
|
||||
// where type.Namespace == null || !type.Namespace.StartsWith("XLua")
|
||||
// select type);
|
||||
// }
|
||||
//}
|
||||
//--------------begin 热补丁自动化配置-------------------------
|
||||
//static bool hasGenericParameter(Type type)
|
||||
//{
|
||||
// if (type.IsGenericTypeDefinition) return true;
|
||||
// if (type.IsGenericParameter) return true;
|
||||
// if (type.IsByRef || type.IsArray)
|
||||
// {
|
||||
// return hasGenericParameter(type.GetElementType());
|
||||
// }
|
||||
// if (type.IsGenericType)
|
||||
// {
|
||||
// foreach (var typeArg in type.GetGenericArguments())
|
||||
// {
|
||||
// if (hasGenericParameter(typeArg))
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
//}
|
||||
|
||||
//static bool typeHasEditorRef(Type type)
|
||||
//{
|
||||
// if (type.Namespace != null && (type.Namespace == "UnityEditor" || type.Namespace.StartsWith("UnityEditor.")))
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// if (type.IsNested)
|
||||
// {
|
||||
// return typeHasEditorRef(type.DeclaringType);
|
||||
// }
|
||||
// if (type.IsByRef || type.IsArray)
|
||||
// {
|
||||
// return typeHasEditorRef(type.GetElementType());
|
||||
// }
|
||||
// if (type.IsGenericType)
|
||||
// {
|
||||
// foreach (var typeArg in type.GetGenericArguments())
|
||||
// {
|
||||
// if (typeHasEditorRef(typeArg))
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
//}
|
||||
|
||||
//static bool delegateHasEditorRef(Type delegateType)
|
||||
//{
|
||||
// if (typeHasEditorRef(delegateType)) return true;
|
||||
// var method = delegateType.GetMethod("Invoke");
|
||||
// if (method == null)
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
// if (typeHasEditorRef(method.ReturnType)) return true;
|
||||
// return method.GetParameters().Any(pinfo => typeHasEditorRef(pinfo.ParameterType));
|
||||
//}
|
||||
|
||||
// 配置某Assembly下所有涉及到的delegate到CSharpCallLua下,Hotfix下拿不准那些delegate需要适配到lua function可以这么配置
|
||||
//[CSharpCallLua]
|
||||
//static IEnumerable<Type> AllDelegate
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// BindingFlags flag = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;
|
||||
// List<Type> allTypes = new List<Type>();
|
||||
// var allAssemblys = new Assembly[]
|
||||
// {
|
||||
// Assembly.Load("Assembly-CSharp")
|
||||
// };
|
||||
// foreach (var t in (from assembly in allAssemblys from type in assembly.GetTypes() select type))
|
||||
// {
|
||||
// var p = t;
|
||||
// while (p != null)
|
||||
// {
|
||||
// allTypes.Add(p);
|
||||
// p = p.BaseType;
|
||||
// }
|
||||
// }
|
||||
// allTypes = allTypes.Distinct().ToList();
|
||||
// var allMethods = from type in allTypes
|
||||
// from method in type.GetMethods(flag)
|
||||
// select method;
|
||||
// var returnTypes = from method in allMethods
|
||||
// select method.ReturnType;
|
||||
// var paramTypes = allMethods.SelectMany(m => m.GetParameters()).Select(pinfo => pinfo.ParameterType.IsByRef ? pinfo.ParameterType.GetElementType() : pinfo.ParameterType);
|
||||
// var fieldTypes = from type in allTypes
|
||||
// from field in type.GetFields(flag)
|
||||
// select field.FieldType;
|
||||
// return (returnTypes.Concat(paramTypes).Concat(fieldTypes)).Where(t => t.BaseType == typeof(MulticastDelegate) && !hasGenericParameter(t) && !delegateHasEditorRef(t)).Distinct();
|
||||
// }
|
||||
//}
|
||||
//--------------end 热补丁自动化配置-------------------------
|
||||
|
||||
//黑名单
|
||||
[BlackList]
|
||||
public static List<List<string>> BlackList = new List<List<string>>() {
|
||||
new List<string>(){"System.Xml.XmlNodeList", "ItemOf"},
|
||||
new List<string>(){"UnityEngine.WWW", "movie"},
|
||||
#if UNITY_WEBGL
|
||||
new List<string>(){"UnityEngine.WWW", "threadPriority"},
|
||||
#endif
|
||||
new List<string>(){"UnityEngine.Texture2D", "alphaIsTransparency"},
|
||||
new List<string>(){"UnityEngine.Security", "GetChainOfTrustValue"},
|
||||
new List<string>(){"UnityEngine.CanvasRenderer", "onRequestRebuild"},
|
||||
new List<string>(){"UnityEngine.Light", "areaSize"},
|
||||
new List<string>(){"UnityEngine.Light", "lightmapBakeType"},
|
||||
new List<string>(){"UnityEngine.WWW", "MovieTexture"},
|
||||
new List<string>(){"UnityEngine.WWW", "GetMovieTexture"},
|
||||
new List<string>(){"UnityEngine.AnimatorOverrideController", "PerformOverrideClipListCleanup"},
|
||||
#if !UNITY_WEBPLAYER
|
||||
new List<string>(){"UnityEngine.Application", "ExternalEval"},
|
||||
#endif
|
||||
new List<string>(){"UnityEngine.GameObject", "networkView"}, //4.6.2 not support
|
||||
new List<string>(){"UnityEngine.Component", "networkView"}, //4.6.2 not support
|
||||
new List<string>(){"System.IO.FileInfo", "GetAccessControl", "System.Security.AccessControl.AccessControlSections"},
|
||||
new List<string>(){"System.IO.FileInfo", "SetAccessControl", "System.Security.AccessControl.FileSecurity"},
|
||||
new List<string>(){"System.IO.DirectoryInfo", "GetAccessControl", "System.Security.AccessControl.AccessControlSections"},
|
||||
new List<string>(){"System.IO.DirectoryInfo", "SetAccessControl", "System.Security.AccessControl.DirectorySecurity"},
|
||||
new List<string>(){"System.IO.DirectoryInfo", "CreateSubdirectory", "System.String", "System.Security.AccessControl.DirectorySecurity"},
|
||||
new List<string>(){"System.IO.DirectoryInfo", "Create", "System.Security.AccessControl.DirectorySecurity"},
|
||||
new List<string>(){"UnityEngine.MonoBehaviour", "runInEditMode"},
|
||||
};
|
||||
|
||||
#if UNITY_2018_1_OR_NEWER
|
||||
[BlackList]
|
||||
public static Func<MemberInfo, bool> MethodFilter = (memberInfo) =>
|
||||
{
|
||||
if (memberInfo.DeclaringType.IsGenericType && memberInfo.DeclaringType.GetGenericTypeDefinition() == typeof(Dictionary<,>))
|
||||
{
|
||||
if (memberInfo.MemberType == MemberTypes.Constructor)
|
||||
{
|
||||
ConstructorInfo constructorInfo = memberInfo as ConstructorInfo;
|
||||
var parameterInfos = constructorInfo.GetParameters();
|
||||
if (parameterInfos.Length > 0)
|
||||
{
|
||||
if (typeof(System.Collections.IEnumerable).IsAssignableFrom(parameterInfos[0].ParameterType))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (memberInfo.MemberType == MemberTypes.Method)
|
||||
{
|
||||
var methodInfo = memberInfo as MethodInfo;
|
||||
if (methodInfo.Name == "TryAdd" || methodInfo.Name == "Remove" && methodInfo.GetParameters().Length == 2)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
#endif
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c81bc5b042a100c43b1eceb1159c9a64
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8473344d97b5b7640aaee952f3cd21f1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a4e9564838e9c8f46ae878c38ac4263a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,20 @@
|
||||
-- Tencent is pleased to support the open source community by making xLua available.
|
||||
-- Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
-- Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
-- http://opensource.org/licenses/MIT
|
||||
-- Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
|
||||
local function snapshot()
|
||||
error('use memory leak checker instead!')
|
||||
end
|
||||
|
||||
--returns the total memory in use by Lua (in Kbytes).
|
||||
local function total()
|
||||
error('use memory leak checker instead!')
|
||||
end
|
||||
|
||||
|
||||
return {
|
||||
snapshot = snapshot,
|
||||
total = total
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0870308a2d502364d8a98c397c66f572
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,125 @@
|
||||
-- Tencent is pleased to support the open source community by making xLua available.
|
||||
-- Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
-- Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
-- http://opensource.org/licenses/MIT
|
||||
-- Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
|
||||
local get_time = os.clock
|
||||
local sethook = xlua.sethook or debug.sethook
|
||||
local func_info_map = nil
|
||||
|
||||
local start_time
|
||||
|
||||
local function create_func_info(db_info)
|
||||
return {
|
||||
db_info = db_info,
|
||||
count = 0,
|
||||
total_time = 0
|
||||
}
|
||||
end
|
||||
|
||||
local function on_hook(event, func_info_id, source)
|
||||
local func_info = func_info_map[func_info_id]
|
||||
if not func_info then
|
||||
func_info = create_func_info(debug.getinfo( 2, 'nS' ))
|
||||
func_info_map[func_info_id] = func_info
|
||||
end
|
||||
if event == "call" then
|
||||
func_info.call_time = get_time()
|
||||
func_info.count = func_info.count + 1
|
||||
func_info.return_time = nil
|
||||
elseif event == "return" or event == 'tail return' then
|
||||
local now = get_time()
|
||||
if func_info.call_time then
|
||||
func_info.total_time = func_info.total_time + (now - func_info.call_time)
|
||||
func_info.call_time = nil
|
||||
else
|
||||
func_info.total_time = func_info.total_time + (now - (func_info.return_time or now))
|
||||
func_info.count = func_info.count + 1
|
||||
end
|
||||
func_info.return_time = now
|
||||
if source and func_info.count == 1 then
|
||||
func_info.db_info.short_src = source
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function start()
|
||||
func_info_map = {}
|
||||
start_time = get_time()
|
||||
sethook(on_hook, 'cr')
|
||||
end
|
||||
|
||||
local function pause()
|
||||
sethook()
|
||||
end
|
||||
|
||||
local function resume()
|
||||
sethook(on_hook, 'cr')
|
||||
end
|
||||
|
||||
local function stop()
|
||||
sethook()
|
||||
func_info_map = nil
|
||||
start_time = nil
|
||||
end
|
||||
|
||||
local function report_output_line(rp, stat_interval)
|
||||
local source = rp.db_info.short_src or '[NA]'
|
||||
local linedefined = (rp.db_info.linedefined and rp.db_info.linedefined >= 0) and string.format(":%i", rp.db_info.linedefined) or ''
|
||||
source = source .. linedefined
|
||||
local name = rp.db_info.name or '[anonymous]'
|
||||
local total_time = string.format("%04.3f", rp.total_time * 1000)
|
||||
local average_time = string.format("%04.3f", rp.total_time / rp.count * 1000)
|
||||
local relative_time = string.format("%03.2f%%", (rp.total_time / stat_interval) * 100 )
|
||||
local count = string.format("%7i", rp.count)
|
||||
|
||||
return string.format("|%-40.40s: %-50.50s: %-12s: %-12s: %-12s: %-12s|\n", name, source, total_time, average_time, relative_time, count)
|
||||
end
|
||||
|
||||
local sort_funcs = {
|
||||
TOTAL = function(a, b) return a.total_time > b.total_time end,
|
||||
AVERAGE = function(a, b) return a.average > b.average end,
|
||||
CALLED = function(a, b) return a.count > b.count end
|
||||
}
|
||||
|
||||
local function report(sort_by)
|
||||
sethook()
|
||||
local sort_func = type(sort_by) == 'function' and sort_by or sort_funcs[sort_by]
|
||||
|
||||
local FORMAT_HEADER_LINE = "|%-40s: %-50s: %-12s: %-12s: %-12s: %-12s|\n"
|
||||
local header = string.format( FORMAT_HEADER_LINE, "FUNCTION", "SOURCE", "TOTAL(MS)", "AVERAGE(MS)", "RELATIVE", "CALLED" )
|
||||
local stat_interval = get_time() - (start_time or get_time())
|
||||
|
||||
local report_list = {}
|
||||
for _, rp in pairs(func_info_map) do
|
||||
table.insert(report_list, {
|
||||
total_time = rp.total_time,
|
||||
count = rp.count,
|
||||
average = rp.total_time / rp.count,
|
||||
output = report_output_line(rp, stat_interval)
|
||||
})
|
||||
end
|
||||
|
||||
table.sort(report_list, sort_func or sort_funcs.TOTAL)
|
||||
|
||||
local output = header
|
||||
|
||||
for i, rp in ipairs(report_list) do
|
||||
output = output .. rp.output
|
||||
end
|
||||
|
||||
sethook(on_hook, 'cr')
|
||||
|
||||
return output
|
||||
end
|
||||
|
||||
return {
|
||||
--开始统计
|
||||
start = start,
|
||||
--获取报告,start和stop之间可以多次调用,参数sort_by类型是string,可以是'TOTAL','AVERAGE', 'CALLED'
|
||||
report = report,
|
||||
--停止统计
|
||||
stop = stop
|
||||
}
|
||||
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: abbd563ad5c00f24c9f2c208ded07aee
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9605de48179dab488d1e430e66883c7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,80 @@
|
||||
-- Tencent is pleased to support the open source community by making xLua available.
|
||||
-- Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
-- Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
-- http://opensource.org/licenses/MIT
|
||||
-- Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
|
||||
require "libtdrlua"
|
||||
local m = {}
|
||||
for k, v in pairs(libtdrlua) do m[k] = v end
|
||||
local load_metalib, load_metalib_buf, free_metalib, get_meta, table2buf, buf2table, str2table, metamaxbufsize, bufalloc, buffree, buf2str
|
||||
load_metalib, m.load_metalib = m.load_metalib, nil
|
||||
load_metalib_buf, m.load_metalib_buf = m.load_metalib_buf, nil
|
||||
free_metalib, m.free_metalib = m.free_metalib, nil
|
||||
get_meta, m.get_meta = m.get_meta, nil
|
||||
table2buf, m.table2buf = m.table2buf, nil
|
||||
buf2table, m.buf2table = m.buf2table, nil
|
||||
str2table, m.str2table = m.str2table, nil
|
||||
buf2str, m.buf2str = m.buf2str, nil
|
||||
|
||||
metamaxbufsize, m.metamaxbufsize = m.metamaxbufsize, nil
|
||||
bufalloc, m.bufalloc = m.bufalloc, nil
|
||||
buffree, m.buffree = m.buffree, nil
|
||||
|
||||
local function create_msg_pk(meta, buf, buf_size)
|
||||
return {
|
||||
buff = buf,
|
||||
pack = function(obj)
|
||||
local ret_code, used_size = table2buf(meta, obj, buf, buf_size, 0)
|
||||
if ret_code ~= 0 then
|
||||
return ret_code, used_size
|
||||
end
|
||||
return buf2str(buf, used_size)
|
||||
end,
|
||||
unpack = function(str)
|
||||
return libtdrlua.str2table(meta, str, 0)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
local function create_lib(metalib)
|
||||
return setmetatable({}, {
|
||||
__index = function(obj, k)
|
||||
local ret_code, meta = libtdrlua.get_meta(metalib, k)
|
||||
if ret_code ~= 0 then
|
||||
error("libtdrlua.get_meta() failed: errno=".. ret_code .. ",msg=" .. meta)
|
||||
end
|
||||
local ret_code, buf_size = libtdrlua.metamaxbufsize(metalib, k)
|
||||
if ret_code ~= 0 then
|
||||
error("libtdrlua.metamaxbufsize() failed: errno=".. ret_code .. ",msg=" .. buf_size)
|
||||
end
|
||||
|
||||
local ret_code, buf = libtdrlua.bufalloc(buf_size)
|
||||
if ret_code ~= 0 then
|
||||
error("libtdrlua.bufalloc() failed: errno=".. ret_code .. ",msg=" .. buf)
|
||||
end
|
||||
|
||||
local pk = create_msg_pk(meta, buf, buf_size)
|
||||
rawset(obj, k, pk)
|
||||
return pk
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
function m.from_file(file)
|
||||
local ret_code, metalib = libtdrlua.load_metalib(file)
|
||||
if ret_code ~= 0 then
|
||||
error("libtdrlua.load_metalib() failed: " .. metalib)
|
||||
end
|
||||
return create_lib(metalib)
|
||||
end
|
||||
|
||||
function m.from_memory(str)
|
||||
local ret_code, metalib = libtdrlua.load_metalib_buf(str)
|
||||
if ret_code ~= 0 then
|
||||
error("libtdrlua.load_metalib_buf() failed: errno=".. ret_code .. ",msg=" .. metalib)
|
||||
end
|
||||
return create_lib(metalib)
|
||||
end
|
||||
|
||||
return m
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a5db3aa3dd58b4e439a84c99eda599c7
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd8e8ebe436974d47b164c99f683adf4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,178 @@
|
||||
-- Tencent is pleased to support the open source community by making xLua available.
|
||||
-- Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
-- Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
-- http://opensource.org/licenses/MIT
|
||||
-- Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
|
||||
local unpack = unpack or table.unpack
|
||||
|
||||
local function async_to_sync(async_func, callback_pos)
|
||||
return function(...)
|
||||
local _co = coroutine.running() or error ('this function must be run in coroutine')
|
||||
local rets
|
||||
local waiting = false
|
||||
local function cb_func(...)
|
||||
if waiting then
|
||||
assert(coroutine.resume(_co, ...))
|
||||
else
|
||||
rets = {...}
|
||||
end
|
||||
end
|
||||
local params = {...}
|
||||
table.insert(params, callback_pos or (#params + 1), cb_func)
|
||||
async_func(unpack(params))
|
||||
if rets == nil then
|
||||
waiting = true
|
||||
rets = {coroutine.yield()}
|
||||
end
|
||||
|
||||
return unpack(rets)
|
||||
end
|
||||
end
|
||||
|
||||
local function coroutine_call(func)
|
||||
return function(...)
|
||||
local co = coroutine.create(func)
|
||||
assert(coroutine.resume(co, ...))
|
||||
end
|
||||
end
|
||||
|
||||
local move_end = {}
|
||||
|
||||
local generator_mt = {
|
||||
__index = {
|
||||
MoveNext = function(self)
|
||||
self.Current = self.co()
|
||||
if self.Current == move_end then
|
||||
self.Current = nil
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
end;
|
||||
Reset = function(self)
|
||||
self.co = coroutine.wrap(self.w_func)
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
local function cs_generator(func, ...)
|
||||
local params = {...}
|
||||
local generator = setmetatable({
|
||||
w_func = function()
|
||||
func(unpack(params))
|
||||
return move_end
|
||||
end
|
||||
}, generator_mt)
|
||||
generator:Reset()
|
||||
return generator
|
||||
end
|
||||
|
||||
local function loadpackage(...)
|
||||
for _, loader in ipairs(package.searchers) do
|
||||
local func = loader(...)
|
||||
if type(func) == 'function' then
|
||||
return func
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function auto_id_map()
|
||||
local hotfix_id_map = require 'hotfix_id_map'
|
||||
local org_hotfix = xlua.hotfix
|
||||
xlua.hotfix = function(cs, field, func)
|
||||
local map_info_of_type = hotfix_id_map[typeof(cs):ToString()]
|
||||
if map_info_of_type then
|
||||
if func == nil then func = false end
|
||||
local tbl = (type(field) == 'table') and field or {[field] = func}
|
||||
for k, v in pairs(tbl) do
|
||||
local map_info_of_methods = map_info_of_type[k]
|
||||
local f = type(v) == 'function' and v or nil
|
||||
for _, id in ipairs(map_info_of_methods or {}) do
|
||||
CS.XLua.HotfixDelegateBridge.Set(id, f)
|
||||
end
|
||||
--CS.XLua.HotfixDelegateBridge.Set(
|
||||
end
|
||||
xlua.private_accessible(cs)
|
||||
else
|
||||
return org_hotfix(cs, field, func)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--和xlua.hotfix的区别是:这个可以调用原来的函数
|
||||
local function hotfix_ex(cs, field, func)
|
||||
assert(type(field) == 'string' and type(func) == 'function', 'invalid argument: #2 string needed, #3 function needed!')
|
||||
local function func_after(...)
|
||||
xlua.hotfix(cs, field, nil)
|
||||
local ret = {func(...)}
|
||||
xlua.hotfix(cs, field, func_after)
|
||||
return unpack(ret)
|
||||
end
|
||||
xlua.hotfix(cs, field, func_after)
|
||||
end
|
||||
|
||||
local function bind(func, obj)
|
||||
return function(...)
|
||||
return func(obj, ...)
|
||||
end
|
||||
end
|
||||
|
||||
--为了兼容luajit,lua53版本直接用|操作符即可
|
||||
local enum_or_op = debug.getmetatable(CS.System.Reflection.BindingFlags.Public).__bor
|
||||
local enum_or_op_ex = function(first, ...)
|
||||
for _, e in ipairs({...}) do
|
||||
first = enum_or_op(first, e)
|
||||
end
|
||||
return first
|
||||
end
|
||||
|
||||
-- description: 直接用C#函数创建delegate
|
||||
local function createdelegate(delegate_cls, obj, impl_cls, method_name, parameter_type_list)
|
||||
local flag = enum_or_op_ex(CS.System.Reflection.BindingFlags.Public, CS.System.Reflection.BindingFlags.NonPublic,
|
||||
CS.System.Reflection.BindingFlags.Instance, CS.System.Reflection.BindingFlags.Static)
|
||||
local m = parameter_type_list and typeof(impl_cls):GetMethod(method_name, flag, nil, parameter_type_list, nil)
|
||||
or typeof(impl_cls):GetMethod(method_name, flag)
|
||||
return CS.System.Delegate.CreateDelegate(typeof(delegate_cls), obj, m)
|
||||
end
|
||||
|
||||
local function state(csobj, state)
|
||||
local csobj_mt = getmetatable(csobj)
|
||||
for k, v in pairs(csobj_mt) do rawset(state, k, v) end
|
||||
local csobj_index, csobj_newindex = state.__index, state.__newindex
|
||||
state.__index = function(obj, k)
|
||||
return rawget(state, k) or csobj_index(obj, k)
|
||||
end
|
||||
state.__newindex = function(obj, k, v)
|
||||
if rawget(state, k) ~= nil then
|
||||
rawset(state, k, v)
|
||||
else
|
||||
csobj_newindex(obj, k, v)
|
||||
end
|
||||
end
|
||||
debug.setmetatable(csobj, state)
|
||||
return state
|
||||
end
|
||||
|
||||
local function print_func_ref_by_csharp()
|
||||
local registry = debug.getregistry()
|
||||
for k, v in pairs(registry) do
|
||||
if type(k) == 'number' and type(v) == 'function' and registry[v] == k then
|
||||
local info = debug.getinfo(v)
|
||||
print(string.format('%s:%d', info.short_src, info.linedefined))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
async_to_sync = async_to_sync,
|
||||
coroutine_call = coroutine_call,
|
||||
cs_generator = cs_generator,
|
||||
loadpackage = loadpackage,
|
||||
auto_id_map = auto_id_map,
|
||||
hotfix_ex = hotfix_ex,
|
||||
bind = bind,
|
||||
createdelegate = createdelegate,
|
||||
state = state,
|
||||
print_func_ref_by_csharp = print_func_ref_by_csharp,
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 499c766e70ccab949b08d91264dc8152
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c17ef3c1b03607b47937ecc16b41e483
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95b951a9c3443844085a894d735e6f5a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making xLua available.
|
||||
* Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
* http://opensource.org/licenses/MIT
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
#if USE_UNI_LUA
|
||||
using LuaAPI = UniLua.Lua;
|
||||
using RealStatePtr = UniLua.ILuaState;
|
||||
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
|
||||
#else
|
||||
using LuaAPI = XLua.LuaDLL.Lua;
|
||||
using RealStatePtr = System.IntPtr;
|
||||
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
|
||||
#endif
|
||||
|
||||
using System;
|
||||
|
||||
namespace XLua
|
||||
{
|
||||
public static partial class CopyByValue
|
||||
{
|
||||
// for int 8
|
||||
public static bool Pack(IntPtr buff, int offset, byte field)
|
||||
{
|
||||
return LuaAPI.xlua_pack_int8_t(buff, offset, field);
|
||||
}
|
||||
public static bool UnPack(IntPtr buff, int offset, out byte field)
|
||||
{
|
||||
return LuaAPI.xlua_unpack_int8_t(buff, offset, out field);
|
||||
}
|
||||
public static bool Pack(IntPtr buff, int offset, sbyte field)
|
||||
{
|
||||
return LuaAPI.xlua_pack_int8_t(buff, offset, (byte)field);
|
||||
}
|
||||
public static bool UnPack(IntPtr buff, int offset, out sbyte field)
|
||||
{
|
||||
byte tfield;
|
||||
bool ret = LuaAPI.xlua_unpack_int8_t(buff, offset, out tfield);
|
||||
field = (sbyte)tfield;
|
||||
return ret;
|
||||
}
|
||||
// for int16
|
||||
public static bool Pack(IntPtr buff, int offset, short field)
|
||||
{
|
||||
return LuaAPI.xlua_pack_int16_t(buff, offset, field);
|
||||
}
|
||||
public static bool UnPack(IntPtr buff, int offset, out short field)
|
||||
{
|
||||
return LuaAPI.xlua_unpack_int16_t(buff, offset, out field);
|
||||
}
|
||||
public static bool Pack(IntPtr buff, int offset, ushort field)
|
||||
{
|
||||
return LuaAPI.xlua_pack_int16_t(buff, offset, (short)field);
|
||||
}
|
||||
public static bool UnPack(IntPtr buff, int offset, out ushort field)
|
||||
{
|
||||
short tfield;
|
||||
bool ret = LuaAPI.xlua_unpack_int16_t(buff, offset, out tfield);
|
||||
field = (ushort)tfield;
|
||||
return ret;
|
||||
}
|
||||
// for int32
|
||||
public static bool Pack(IntPtr buff, int offset, int field)
|
||||
{
|
||||
return LuaAPI.xlua_pack_int32_t(buff, offset, field);
|
||||
}
|
||||
public static bool UnPack(IntPtr buff, int offset, out int field)
|
||||
{
|
||||
return LuaAPI.xlua_unpack_int32_t(buff, offset, out field);
|
||||
}
|
||||
public static bool Pack(IntPtr buff, int offset, uint field)
|
||||
{
|
||||
return LuaAPI.xlua_pack_int32_t(buff, offset, (int)field);
|
||||
}
|
||||
public static bool UnPack(IntPtr buff, int offset, out uint field)
|
||||
{
|
||||
int tfield;
|
||||
bool ret = LuaAPI.xlua_unpack_int32_t(buff, offset, out tfield);
|
||||
field = (uint)tfield;
|
||||
return ret;
|
||||
}
|
||||
// for int64
|
||||
public static bool Pack(IntPtr buff, int offset, long field)
|
||||
{
|
||||
return LuaAPI.xlua_pack_int64_t(buff, offset, field);
|
||||
}
|
||||
public static bool UnPack(IntPtr buff, int offset, out long field)
|
||||
{
|
||||
return LuaAPI.xlua_unpack_int64_t(buff, offset, out field);
|
||||
}
|
||||
public static bool Pack(IntPtr buff, int offset, ulong field)
|
||||
{
|
||||
return LuaAPI.xlua_pack_int64_t(buff, offset, (long)field);
|
||||
}
|
||||
public static bool UnPack(IntPtr buff, int offset, out ulong field)
|
||||
{
|
||||
long tfield;
|
||||
bool ret = LuaAPI.xlua_unpack_int64_t(buff, offset, out tfield);
|
||||
field = (ulong)tfield;
|
||||
return ret;
|
||||
}
|
||||
// for float
|
||||
public static bool Pack(IntPtr buff, int offset, float field)
|
||||
{
|
||||
return LuaAPI.xlua_pack_float(buff, offset, field);
|
||||
}
|
||||
public static bool UnPack(IntPtr buff, int offset, out float field)
|
||||
{
|
||||
return LuaAPI.xlua_unpack_float(buff, offset, out field);
|
||||
}
|
||||
// for double
|
||||
public static bool Pack(IntPtr buff, int offset, double field)
|
||||
{
|
||||
return LuaAPI.xlua_pack_double(buff, offset, field);
|
||||
}
|
||||
public static bool UnPack(IntPtr buff, int offset, out double field)
|
||||
{
|
||||
return LuaAPI.xlua_unpack_double(buff, offset, out field);
|
||||
}
|
||||
// for decimal
|
||||
public static bool Pack(IntPtr buff, int offset, decimal field)
|
||||
{
|
||||
return LuaAPI.xlua_pack_decimal(buff, offset, ref field);
|
||||
}
|
||||
public static bool UnPack(IntPtr buff, int offset, out decimal field)
|
||||
{
|
||||
byte scale;
|
||||
byte sign;
|
||||
int hi32;
|
||||
ulong lo64;
|
||||
if (!LuaAPI.xlua_unpack_decimal(buff, offset, out scale, out sign, out hi32, out lo64))
|
||||
{
|
||||
field = default(decimal);
|
||||
return false;
|
||||
}
|
||||
|
||||
field = new Decimal((int)(lo64 & 0xFFFFFFFF), (int)(lo64 >> 32), hi32, (sign & 0x80) != 0, scale);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool IsStruct(Type type)
|
||||
{
|
||||
return type.IsValueType() && !type.IsEnum() && !type.IsPrimitive();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4efe0ed849f28a64b9a5423f228009cf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,246 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making xLua available.
|
||||
* Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
* http://opensource.org/licenses/MIT
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
#if USE_UNI_LUA
|
||||
using LuaAPI = UniLua.Lua;
|
||||
using RealStatePtr = UniLua.ILuaState;
|
||||
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
|
||||
#else
|
||||
using LuaAPI = XLua.LuaDLL.Lua;
|
||||
using RealStatePtr = System.IntPtr;
|
||||
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
|
||||
#endif
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace XLua
|
||||
{
|
||||
public abstract class DelegateBridgeBase : LuaBase
|
||||
{
|
||||
private Type firstKey = null;
|
||||
|
||||
private Delegate firstValue = null;
|
||||
|
||||
private Dictionary<Type, Delegate> bindTo = null;
|
||||
|
||||
protected int errorFuncRef;
|
||||
|
||||
public DelegateBridgeBase(int reference, LuaEnv luaenv) : base(reference, luaenv)
|
||||
{
|
||||
errorFuncRef = luaenv.errorFuncRef;
|
||||
}
|
||||
|
||||
public bool TryGetDelegate(Type key, out Delegate value)
|
||||
{
|
||||
if(key == firstKey)
|
||||
{
|
||||
value = firstValue;
|
||||
return true;
|
||||
}
|
||||
if (bindTo != null)
|
||||
{
|
||||
return bindTo.TryGetValue(key, out value);
|
||||
}
|
||||
value = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void AddDelegate(Type key, Delegate value)
|
||||
{
|
||||
if (key == firstKey)
|
||||
{
|
||||
throw new ArgumentException("An element with the same key already exists in the dictionary.");
|
||||
}
|
||||
|
||||
if (firstKey == null && bindTo == null) // nothing
|
||||
{
|
||||
firstKey = key;
|
||||
firstValue = value;
|
||||
}
|
||||
else if (firstKey != null && bindTo == null) // one key existed
|
||||
{
|
||||
bindTo = new Dictionary<Type, Delegate>();
|
||||
bindTo.Add(firstKey, firstValue);
|
||||
firstKey = null;
|
||||
firstValue = null;
|
||||
bindTo.Add(key, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
bindTo.Add(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Delegate GetDelegateByType(Type type)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class HotfixDelegateBridge
|
||||
{
|
||||
#if (UNITY_IPHONE || UNITY_TVOS) && !UNITY_EDITOR
|
||||
[DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_get_hotfix_flag(int idx);
|
||||
|
||||
|
||||
[DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void xlua_set_hotfix_flag(int idx, bool flag);
|
||||
#else
|
||||
public static bool xlua_get_hotfix_flag(int idx)
|
||||
{
|
||||
return (idx < DelegateBridge.DelegateBridgeList.Length) && (DelegateBridge.DelegateBridgeList[idx] != null);
|
||||
}
|
||||
#endif
|
||||
|
||||
public static DelegateBridge Get(int idx)
|
||||
{
|
||||
return DelegateBridge.DelegateBridgeList[idx];
|
||||
}
|
||||
|
||||
public static void Set(int idx, DelegateBridge val)
|
||||
{
|
||||
if (idx >= DelegateBridge.DelegateBridgeList.Length)
|
||||
{
|
||||
DelegateBridge[] newList = new DelegateBridge[idx + 1];
|
||||
for (int i = 0; i < DelegateBridge.DelegateBridgeList.Length; i++)
|
||||
{
|
||||
newList[i] = DelegateBridge.DelegateBridgeList[i];
|
||||
}
|
||||
DelegateBridge.DelegateBridgeList = newList;
|
||||
}
|
||||
DelegateBridge.DelegateBridgeList[idx] = val;
|
||||
#if (UNITY_IPHONE || UNITY_TVOS) && !UNITY_EDITOR
|
||||
xlua_set_hotfix_flag(idx, val != null);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public partial class DelegateBridge : DelegateBridgeBase
|
||||
{
|
||||
internal static DelegateBridge[] DelegateBridgeList = new DelegateBridge[0];
|
||||
|
||||
public static bool Gen_Flag = false;
|
||||
|
||||
public DelegateBridge(int reference, LuaEnv luaenv) : base(reference, luaenv)
|
||||
{
|
||||
}
|
||||
|
||||
public void PCall(IntPtr L, int nArgs, int nResults, int errFunc)
|
||||
{
|
||||
if (LuaAPI.lua_pcall(L, nArgs, nResults, errFunc) != 0)
|
||||
luaEnv.ThrowExceptionFromError(errFunc - 1);
|
||||
}
|
||||
|
||||
#if HOTFIX_ENABLE
|
||||
|
||||
private int _oldTop = 0;
|
||||
private Stack<int> _stack = new Stack<int>();
|
||||
|
||||
public void InvokeSessionStart()
|
||||
{
|
||||
System.Threading.Monitor.Enter(luaEnv.luaEnvLock);
|
||||
var L = luaEnv.L;
|
||||
_stack.Push(_oldTop);
|
||||
_oldTop = LuaAPI.lua_gettop(L);
|
||||
LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
}
|
||||
|
||||
public void Invoke(int nRet)
|
||||
{
|
||||
int error = LuaAPI.lua_pcall(luaEnv.L, LuaAPI.lua_gettop(luaEnv.L) - _oldTop - 2, nRet, _oldTop + 1);
|
||||
if (error != 0)
|
||||
{
|
||||
var lastOldTop = _oldTop;
|
||||
_oldTop = _stack.Pop();
|
||||
System.Threading.Monitor.Exit(luaEnv.luaEnvLock);
|
||||
luaEnv.ThrowExceptionFromError(lastOldTop);
|
||||
}
|
||||
}
|
||||
|
||||
public void InvokeSessionEnd()
|
||||
{
|
||||
LuaAPI.lua_settop(luaEnv.L, _oldTop);
|
||||
_oldTop = _stack.Pop();
|
||||
System.Threading.Monitor.Exit(luaEnv.luaEnvLock);
|
||||
}
|
||||
|
||||
public TResult InvokeSessionEndWithResult<TResult>()
|
||||
{
|
||||
if (LuaAPI.lua_gettop(luaEnv.L) < _oldTop + 2)
|
||||
{
|
||||
InvokeSessionEnd();
|
||||
throw new InvalidOperationException("no result!");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
TResult ret;
|
||||
luaEnv.translator.Get(luaEnv.L, _oldTop + 2, out ret);
|
||||
return ret;
|
||||
}
|
||||
finally
|
||||
{
|
||||
InvokeSessionEnd();
|
||||
}
|
||||
}
|
||||
|
||||
public void InParam<T>(T p)
|
||||
{
|
||||
try
|
||||
{
|
||||
luaEnv.translator.PushByType(luaEnv.L, p);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
InvokeSessionEnd();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public void InParams<T>(T[] ps)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < ps.Length; i++)
|
||||
{
|
||||
luaEnv.translator.PushByType<T>(luaEnv.L, ps[i]);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
InvokeSessionEnd();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
//pos start from 0
|
||||
public void OutParam<TResult>(int pos, out TResult ret)
|
||||
{
|
||||
if (LuaAPI.lua_gettop(luaEnv.L) < _oldTop + 2 + pos)
|
||||
{
|
||||
InvokeSessionEnd();
|
||||
throw new InvalidOperationException("no result in " + pos);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
luaEnv.translator.Get(luaEnv.L, _oldTop + 2 + pos, out ret);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
InvokeSessionEnd();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9bd47cb21c6363741a20a12b82003ebc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b604b9556abedc84db4f97700190407e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3129589b138e7c24e91049eefae8d255
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2df52722b237505409bd5c3bf0a56e3f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d816cdfd73372c343865d7743b69d8b7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,34 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using XLua;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using CSObjectWrapEditor;
|
||||
|
||||
public class LinkXmlGen : ScriptableObject
|
||||
{
|
||||
public TextAsset Template;
|
||||
|
||||
public static IEnumerable<CustomGenTask> GetTasks(LuaEnv lua_env, UserConfig user_cfg)
|
||||
{
|
||||
LuaTable data = lua_env.NewTable();
|
||||
var assembly_infos = (from type in (user_cfg.ReflectionUse.Concat(user_cfg.LuaCallCSharp))
|
||||
group type by type.Assembly.GetName().Name into assembly_info
|
||||
select new { FullName = assembly_info.Key, Types = assembly_info.ToList()}).ToList();
|
||||
data.Set("assembly_infos", assembly_infos);
|
||||
|
||||
yield return new CustomGenTask
|
||||
{
|
||||
Data = data,
|
||||
Output = new StreamWriter(GeneratorConfig.common_path + "/link.xml",
|
||||
false, Encoding.UTF8)
|
||||
};
|
||||
}
|
||||
|
||||
[GenCodeMenu]//加到Generate Code菜单里头
|
||||
public static void GenLinkXml()
|
||||
{
|
||||
Generator.CustomGen(ScriptableObject.CreateInstance<LinkXmlGen>().Template.text, GetTasks);
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0ec9fb595129eb498b8c0f2f2e2b194
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,13 @@
|
||||
<%
|
||||
require "TemplateCommon"
|
||||
%>
|
||||
|
||||
<linker>
|
||||
<%ForEachCsList(assembly_infos, function(assembly_info)%>
|
||||
<assembly fullname="<%=assembly_info.FullName%>">
|
||||
<%ForEachCsList(assembly_info.Types, function(type)
|
||||
%><type fullname="<%=type:ToString()%>" preserve="all"/>
|
||||
<%end)%>
|
||||
</assembly>
|
||||
<%end)%>
|
||||
</linker>
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 172f735757c40a04381b136c3690967b
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c45243c22eb0fba4a975fa81bfd91033
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,589 @@
|
||||
#if USE_UNI_LUA
|
||||
using LuaAPI = UniLua.Lua;
|
||||
using RealStatePtr = UniLua.ILuaState;
|
||||
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
|
||||
#else
|
||||
using LuaAPI = XLua.LuaDLL.Lua;
|
||||
using RealStatePtr = System.IntPtr;
|
||||
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
|
||||
#endif
|
||||
|
||||
using XLua;
|
||||
using System.Collections.Generic;
|
||||
<%ForEachCsList(namespaces, function(namespace)%>using <%=namespace%>;<%end)%>
|
||||
<%
|
||||
require "TemplateCommon"
|
||||
|
||||
local OpNameMap = {
|
||||
op_Addition = "__AddMeta",
|
||||
op_Subtraction = "__SubMeta",
|
||||
op_Multiply = "__MulMeta",
|
||||
op_Division = "__DivMeta",
|
||||
op_Equality = "__EqMeta",
|
||||
op_UnaryNegation = "__UnmMeta",
|
||||
op_LessThan = "__LTMeta",
|
||||
op_LessThanOrEqual = "__LEMeta",
|
||||
op_Modulus = "__ModMeta",
|
||||
op_BitwiseAnd = "__BandMeta",
|
||||
op_BitwiseOr = "__BorMeta",
|
||||
op_ExclusiveOr = "__BxorMeta",
|
||||
op_OnesComplement = "__BnotMeta",
|
||||
op_LeftShift = "__ShlMeta",
|
||||
op_RightShift = "__ShrMeta",
|
||||
}
|
||||
|
||||
local OpCallNameMap = {
|
||||
op_Addition = "+",
|
||||
op_Subtraction = "-",
|
||||
op_Multiply = "*",
|
||||
op_Division = "/",
|
||||
op_Equality = "==",
|
||||
op_UnaryNegation = "-",
|
||||
op_LessThan = "<",
|
||||
op_LessThanOrEqual = "<=",
|
||||
op_Modulus = "%",
|
||||
op_BitwiseAnd = "&",
|
||||
op_BitwiseOr = "|",
|
||||
op_ExclusiveOr = "^",
|
||||
op_OnesComplement = "~",
|
||||
op_LeftShift = "<<",
|
||||
op_RightShift = ">>",
|
||||
}
|
||||
|
||||
local obj_method_count = 0
|
||||
local obj_getter_count = 0
|
||||
local obj_setter_count = 0
|
||||
local meta_func_count = operators.Count
|
||||
local cls_field_count = 1
|
||||
local cls_getter_count = 0
|
||||
local cls_setter_count = 0
|
||||
|
||||
ForEachCsList(methods, function(method)
|
||||
if method.IsStatic then
|
||||
cls_field_count = cls_field_count + 1
|
||||
else
|
||||
obj_method_count = obj_method_count + 1
|
||||
end
|
||||
end)
|
||||
|
||||
ForEachCsList(events, function(event)
|
||||
if event.IsStatic then
|
||||
cls_field_count = cls_field_count + 1
|
||||
else
|
||||
obj_method_count = obj_method_count + 1
|
||||
end
|
||||
end)
|
||||
|
||||
ForEachCsList(getters, function(getter)
|
||||
if getter.IsStatic then
|
||||
if getter.ReadOnly then
|
||||
cls_field_count = cls_field_count + 1
|
||||
else
|
||||
cls_getter_count = cls_getter_count + 1
|
||||
end
|
||||
else
|
||||
obj_getter_count = obj_getter_count + 1
|
||||
end
|
||||
end)
|
||||
|
||||
ForEachCsList(setters, function(setter)
|
||||
if setter.IsStatic then
|
||||
cls_setter_count = cls_setter_count + 1
|
||||
else
|
||||
obj_setter_count = obj_setter_count + 1
|
||||
end
|
||||
end)
|
||||
|
||||
ForEachCsList(lazymembers, function(lazymember)
|
||||
if lazymember.IsStatic == 'true' then
|
||||
if 'CLS_IDX' == lazymember.Index then
|
||||
cls_field_count = cls_field_count + 1
|
||||
elseif 'CLS_GETTER_IDX' == lazymember.Index then
|
||||
cls_getter_count = cls_getter_count + 1
|
||||
elseif 'CLS_SETTER_IDX' == lazymember.Index then
|
||||
cls_setter_count = cls_setter_count + 1
|
||||
end
|
||||
else
|
||||
if 'METHOD_IDX' == lazymember.Index then
|
||||
obj_method_count = obj_method_count + 1
|
||||
elseif 'GETTER_IDX' == lazymember.Index then
|
||||
obj_getter_count = obj_getter_count + 1
|
||||
elseif 'SETTER_IDX' == lazymember.Index then
|
||||
obj_setter_count = obj_setter_count + 1
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
local generic_arg_list, type_constraints = GenericArgumentList(type)
|
||||
|
||||
%>
|
||||
namespace XLua.CSObjectWrap
|
||||
{
|
||||
using Utils = XLua.Utils;
|
||||
public class <%=CSVariableName(type)%>Wrap<%=generic_arg_list%> <%=type_constraints%>
|
||||
{
|
||||
public static void __Register(RealStatePtr L)
|
||||
{
|
||||
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
||||
System.Type type = typeof(<%=CsFullTypeName(type)%>);
|
||||
Utils.BeginObjectRegister(type, L, translator, <%=meta_func_count%>, <%=obj_method_count%>, <%=obj_getter_count%>, <%=obj_setter_count%>);
|
||||
<%ForEachCsList(operators, function(operator)%>Utils.RegisterFunc(L, Utils.OBJ_META_IDX, "<%=(OpNameMap[operator.Name]):gsub('Meta', ''):lower()%>", <%=OpNameMap[operator.Name]%>);
|
||||
<%end)%>
|
||||
<%ForEachCsList(methods, function(method) if not method.IsStatic then %>Utils.RegisterFunc(L, Utils.METHOD_IDX, "<%=method.Name%>", _m_<%=method.Name%>);
|
||||
<% end end)%>
|
||||
<%ForEachCsList(events, function(event) if not event.IsStatic then %>Utils.RegisterFunc(L, Utils.METHOD_IDX, "<%=event.Name%>", _e_<%=event.Name%>);
|
||||
<% end end)%>
|
||||
<%ForEachCsList(getters, function(getter) if not getter.IsStatic then %>Utils.RegisterFunc(L, Utils.GETTER_IDX, "<%=getter.Name%>", _g_get_<%=getter.Name%>);
|
||||
<%end end)%>
|
||||
<%ForEachCsList(setters, function(setter) if not setter.IsStatic then %>Utils.RegisterFunc(L, Utils.SETTER_IDX, "<%=setter.Name%>", _s_set_<%=setter.Name%>);
|
||||
<%end end)%>
|
||||
<%ForEachCsList(lazymembers, function(lazymember) if lazymember.IsStatic == 'false' then %>Utils.RegisterLazyFunc(L, Utils.<%=lazymember.Index%>, "<%=lazymember.Name%>", type, <%=lazymember.MemberType%>, <%=lazymember.IsStatic%>);
|
||||
<%end end)%>
|
||||
Utils.EndObjectRegister(type, L, translator, <% if type.IsArray or ((indexers.Count or 0) > 0) then %>__CSIndexer<%else%>null<%end%>, <%if type.IsArray or ((newindexers.Count or 0) > 0) then%>__NewIndexer<%else%>null<%end%>,
|
||||
null, null, null);
|
||||
|
||||
Utils.BeginClassRegister(type, L, __CreateInstance, <%=cls_field_count%>, <%=cls_getter_count%>, <%=cls_setter_count%>);
|
||||
<%ForEachCsList(methods, function(method) if method.IsStatic then %>Utils.RegisterFunc(L, Utils.CLS_IDX, "<%=method.Overloads[0].Name%>", _m_<%=method.Name%>);
|
||||
<% end end)%>
|
||||
<%ForEachCsList(events, function(event) if event.IsStatic then %>Utils.RegisterFunc(L, Utils.CLS_IDX, "<%=event.Name%>", _e_<%=event.Name%>);
|
||||
<% end end)%>
|
||||
<%ForEachCsList(getters, function(getter) if getter.IsStatic and getter.ReadOnly then %>Utils.RegisterObject(L, translator, Utils.CLS_IDX, "<%=getter.Name%>", <%=CsFullTypeName(type).."."..getter.Name%>);
|
||||
<%end end)%>
|
||||
<%ForEachCsList(getters, function(getter) if getter.IsStatic and (not getter.ReadOnly) then %>Utils.RegisterFunc(L, Utils.CLS_GETTER_IDX, "<%=getter.Name%>", _g_get_<%=getter.Name%>);
|
||||
<%end end)%>
|
||||
<%ForEachCsList(setters, function(setter) if setter.IsStatic then %>Utils.RegisterFunc(L, Utils.CLS_SETTER_IDX, "<%=setter.Name%>", _s_set_<%=setter.Name%>);
|
||||
<%end end)%>
|
||||
<%ForEachCsList(lazymembers, function(lazymember) if lazymember.IsStatic == 'true' then %>Utils.RegisterLazyFunc(L, Utils.<%=lazymember.Index%>, "<%=lazymember.Name%>", type, <%=lazymember.MemberType%>, <%=lazymember.IsStatic%>);
|
||||
<%end end)%>
|
||||
Utils.EndClassRegister(type, L, translator);
|
||||
}
|
||||
|
||||
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
||||
static int __CreateInstance(RealStatePtr L)
|
||||
{
|
||||
<%
|
||||
if constructors.Count == 0 and (not type.IsValueType) then
|
||||
%>return LuaAPI.luaL_error(L, "<%=CsFullTypeName(type)%> does not have a constructor!");<%
|
||||
else %>
|
||||
try {
|
||||
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
||||
<%
|
||||
local hasZeroParamsCtor = false
|
||||
ForEachCsList(constructors, function(constructor, ci)
|
||||
local parameters = constructor:GetParameters()
|
||||
if parameters.Length == 0 then
|
||||
hasZeroParamsCtor = true
|
||||
end
|
||||
local def_count = constructor_def_vals[ci]
|
||||
local param_count = parameters.Length
|
||||
local in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)
|
||||
local out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)
|
||||
local real_param_count = param_count - def_count
|
||||
local has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])
|
||||
local in_pos = 0
|
||||
%>if(LuaAPI.lua_gettop(L) <%=has_v_params and ">=" or "=="%> <%=in_num + 1 - def_count - (has_v_params and 1 or 0)%><%ForEachCsList(parameters, function(parameter, pi)
|
||||
if pi >= real_param_count then return end
|
||||
local parameterType = parameter.ParameterType
|
||||
if has_v_params and pi == param_count - 1 then parameterType = parameterType:GetElementType() end
|
||||
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then in_pos = in_pos + 1
|
||||
%> && <%=GetCheckStatement(parameterType, in_pos+1, has_v_params and pi == param_count - 1)%><%
|
||||
end
|
||||
end)%>)
|
||||
{
|
||||
<%ForEachCsList(parameters, function(parameter, pi)
|
||||
if pi >= real_param_count then return end
|
||||
%><%=GetCasterStatement(parameter.ParameterType, pi+2, LocalName(parameter.Name), true, has_v_params and pi == param_count - 1)%>;
|
||||
<%end)%>
|
||||
<%=CsFullTypeName(type)%> gen_ret = new <%=CsFullTypeName(type)%>(<%ForEachCsList(parameters, function(parameter, pi) if pi >= real_param_count then return end; if pi ~=0 then %><%=', '%><% end ;if parameter.IsOut and parameter.ParameterType.IsByRef then %>out <% elseif parameter.ParameterType.IsByRef then %>ref <% end %><%=LocalName(parameter.Name)%><% end)%>);
|
||||
<%=GetPushStatement(type, "gen_ret")%>;
|
||||
<%local in_pos = 0
|
||||
ForEachCsList(parameters, function(parameter, pi)
|
||||
if pi >= real_param_count then return end
|
||||
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
|
||||
in_pos = in_pos + 1
|
||||
end
|
||||
if parameter.ParameterType.IsByRef then
|
||||
%><%=GetPushStatement(parameter.ParameterType:GetElementType(), LocalName(parameter.Name))%>;
|
||||
<%if not parameter.IsOut and parameter.ParameterType.IsByRef and NeedUpdate(parameter.ParameterType) then
|
||||
%><%=GetUpdateStatement(parameter.ParameterType:GetElementType(), in_pos+1, LocalName(parameter.Name))%>;
|
||||
<%end%>
|
||||
<%
|
||||
end
|
||||
end)
|
||||
%>
|
||||
return <%=out_num + 1%>;
|
||||
}
|
||||
<%end)
|
||||
if (not hasZeroParamsCtor) and type.IsValueType then
|
||||
%>
|
||||
if (LuaAPI.lua_gettop(L) == 1)
|
||||
{
|
||||
<%=GetPushStatement(type, "default(" .. CsFullTypeName(type).. ")")%>;
|
||||
return 1;
|
||||
}
|
||||
<%end%>
|
||||
}
|
||||
catch(System.Exception gen_e) {
|
||||
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
||||
}
|
||||
return LuaAPI.luaL_error(L, "invalid arguments to <%=CsFullTypeName(type)%> constructor!");
|
||||
<% end %>
|
||||
}
|
||||
|
||||
<% if type.IsArray or ((indexers.Count or 0) > 0) then %>
|
||||
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
||||
public static int __CSIndexer(RealStatePtr L)
|
||||
{
|
||||
<%if type.IsArray then %>
|
||||
try {
|
||||
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
||||
|
||||
if (<%=GetCheckStatement(type, 1)%> && LuaAPI.lua_isnumber(L, 2))
|
||||
{
|
||||
int index = (int)LuaAPI.lua_tonumber(L, 2);
|
||||
<%=GetSelfStatement(type)%>;
|
||||
LuaAPI.lua_pushboolean(L, true);
|
||||
<%=GetPushStatement(type:GetElementType(), "gen_to_be_invoked[index]")%>;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
catch(System.Exception gen_e) {
|
||||
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
||||
}
|
||||
<%elseif indexers.Count > 0 then
|
||||
%>try {
|
||||
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
||||
<%
|
||||
ForEachCsList(indexers, function(indexer)
|
||||
local paramter = indexer:GetParameters()[0]
|
||||
%>
|
||||
if (<%=GetCheckStatement(type, 1)%> && <%=GetCheckStatement(paramter.ParameterType, 2)%>)
|
||||
{
|
||||
|
||||
<%=GetSelfStatement(type)%>;
|
||||
<%=GetCasterStatement(paramter.ParameterType, 2, "index", true)%>;
|
||||
LuaAPI.lua_pushboolean(L, true);
|
||||
<%=GetPushStatement(indexer.ReturnType, "gen_to_be_invoked[index]")%>;
|
||||
return 2;
|
||||
}
|
||||
<%end)%>
|
||||
}
|
||||
catch(System.Exception gen_e) {
|
||||
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
||||
}
|
||||
<%end%>
|
||||
LuaAPI.lua_pushboolean(L, false);
|
||||
return 1;
|
||||
}
|
||||
<% end %>
|
||||
|
||||
<%if type.IsArray or ((newindexers.Count or 0) > 0) then%>
|
||||
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
||||
public static int __NewIndexer(RealStatePtr L)
|
||||
{
|
||||
<%if type.IsArray or newindexers.Count > 0 then %>ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);<%end%>
|
||||
<%if type.IsArray then
|
||||
local elementType = type:GetElementType()
|
||||
%>
|
||||
try {
|
||||
if (<%=GetCheckStatement(type, 1)%> && LuaAPI.lua_isnumber(L, 2) && <%=GetCheckStatement(elementType, 3)%>)
|
||||
{
|
||||
int index = (int)LuaAPI.lua_tonumber(L, 2);
|
||||
<%=GetSelfStatement(type)%>;
|
||||
<%=GetCasterStatement(elementType, 3, "gen_to_be_invoked[index]")%>;
|
||||
LuaAPI.lua_pushboolean(L, true);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
catch(System.Exception gen_e) {
|
||||
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
||||
}
|
||||
<%elseif newindexers.Count > 0 then%>
|
||||
try {
|
||||
<%ForEachCsList(newindexers, function(newindexer)
|
||||
local keyType = newindexer:GetParameters()[0].ParameterType
|
||||
local valueType = newindexer:GetParameters()[1].ParameterType
|
||||
%>
|
||||
if (<%=GetCheckStatement(type, 1)%> && <%=GetCheckStatement(keyType, 2)%> && <%=GetCheckStatement(valueType, 3)%>)
|
||||
{
|
||||
|
||||
<%=GetSelfStatement(type)%>;
|
||||
<%=GetCasterStatement(keyType, 2, "key", true)%>;
|
||||
<%if IsStruct(valueType) then%><%=GetCasterStatement(valueType, 3, "gen_value", true)%>;
|
||||
gen_to_be_invoked[key] = gen_value;<%else
|
||||
%><%=GetCasterStatement(valueType, 3, "gen_to_be_invoked[key]")%>;<%end%>
|
||||
LuaAPI.lua_pushboolean(L, true);
|
||||
return 1;
|
||||
}
|
||||
<%end)%>
|
||||
}
|
||||
catch(System.Exception gen_e) {
|
||||
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
||||
}
|
||||
<%end%>
|
||||
LuaAPI.lua_pushboolean(L, false);
|
||||
return 1;
|
||||
}
|
||||
<% end %>
|
||||
|
||||
<%ForEachCsList(operators, function(operator) %>
|
||||
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
||||
static int <%=OpNameMap[operator.Name]%>(RealStatePtr L)
|
||||
{
|
||||
<% if operator.Name ~= "op_UnaryNegation" and operator.Name ~= "op_OnesComplement" then %>
|
||||
try {
|
||||
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
||||
<%ForEachCsList(operator.Overloads, function(overload)
|
||||
local left_param = overload:GetParameters()[0]
|
||||
local right_param = overload:GetParameters()[1]
|
||||
%>
|
||||
|
||||
if (<%=GetCheckStatement(left_param.ParameterType, 1)%> && <%=GetCheckStatement(right_param.ParameterType, 2)%>)
|
||||
{
|
||||
<%=GetCasterStatement(left_param.ParameterType, 1, "leftside", true)%>;
|
||||
<%=GetCasterStatement(right_param.ParameterType, 2, "rightside", true)%>;
|
||||
|
||||
<%=GetPushStatement(overload.ReturnType, "leftside " .. OpCallNameMap[operator.Name] .. " rightside")%>;
|
||||
|
||||
return 1;
|
||||
}
|
||||
<%end)%>
|
||||
}
|
||||
catch(System.Exception gen_e) {
|
||||
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
||||
}
|
||||
return LuaAPI.luaL_error(L, "invalid arguments to right hand of <%=OpCallNameMap[operator.Name]%> operator, need <%=CsFullTypeName(type)%>!");
|
||||
<%else%>
|
||||
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
||||
try {
|
||||
<%=GetCasterStatement(type, 1, "rightside", true)%>;
|
||||
<%=GetPushStatement(operator.Overloads[0].ReturnType, OpCallNameMap[operator.Name] .. " rightside")%>;
|
||||
} catch(System.Exception gen_e) {
|
||||
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
||||
}
|
||||
return 1;
|
||||
<%end%>
|
||||
}
|
||||
<%end)%>
|
||||
|
||||
<%ForEachCsList(methods, function(method)%>
|
||||
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
||||
static int _m_<%=method.Name%>(RealStatePtr L)
|
||||
{
|
||||
try {
|
||||
<%
|
||||
local need_obj = not method.IsStatic
|
||||
if MethodCallNeedTranslator(method) then
|
||||
%>
|
||||
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
||||
<%end%>
|
||||
<%if need_obj then%>
|
||||
<%=GetSelfStatement(type)%>;
|
||||
<%end%>
|
||||
<%if method.Overloads.Count > 1 then%>
|
||||
int gen_param_count = LuaAPI.lua_gettop(L);
|
||||
<%end%>
|
||||
<%ForEachCsList(method.Overloads, function(overload, oi)
|
||||
local parameters = MethodParameters(overload)
|
||||
local in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)
|
||||
local param_offset = method.IsStatic and 0 or 1
|
||||
local out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)
|
||||
local in_pos = 0
|
||||
local has_return = (overload.ReturnType.FullName ~= "System.Void")
|
||||
local def_count = method.DefaultValues[oi]
|
||||
local param_count = parameters.Length
|
||||
local real_param_count = param_count - def_count
|
||||
local has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])
|
||||
if method.Overloads.Count > 1 then
|
||||
%>if(gen_param_count <%=has_v_params and ">=" or "=="%> <%=in_num+param_offset-def_count - (has_v_params and 1 or 0)%><%
|
||||
ForEachCsList(parameters, function(parameter, pi)
|
||||
if pi >= real_param_count then return end
|
||||
local parameterType = parameter.ParameterType
|
||||
if has_v_params and pi == param_count - 1 then parameterType = parameterType:GetElementType() end
|
||||
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then in_pos = in_pos + 1;
|
||||
%>&& <%=GetCheckStatement(parameterType , in_pos+param_offset, has_v_params and pi == param_count - 1)%><%
|
||||
end
|
||||
end)%>) <%end%>
|
||||
{
|
||||
<%if overload.Name == "get_Item" and overload.IsSpecialName then
|
||||
local keyType = overload:GetParameters()[0].ParameterType%>
|
||||
<%=GetCasterStatement(keyType, 2, "key", true)%>;
|
||||
<%=GetPushStatement(overload.ReturnType, "gen_to_be_invoked[key]")%>;
|
||||
<%elseif overload.Name == "set_Item" and overload.IsSpecialName then
|
||||
local keyType = overload:GetParameters()[0].ParameterType
|
||||
local valueType = overload:GetParameters()[1].ParameterType%>
|
||||
<%=GetCasterStatement(keyType, 2, "key", true)%>;
|
||||
<%=GetCasterStatement(valueType, 3, "gen_value", true)%>;
|
||||
gen_to_be_invoked[key] = gen_value;
|
||||
<% else
|
||||
in_pos = 0;
|
||||
ForEachCsList(parameters, function(parameter, pi)
|
||||
if pi >= real_param_count then return end
|
||||
%><%if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
|
||||
in_pos = in_pos + 1
|
||||
%><%=GetCasterStatement(parameter.ParameterType, in_pos+param_offset, LocalName(parameter.Name), true, has_v_params and pi == param_count - 1)%><%
|
||||
else%><%=CsFullTypeName(parameter.ParameterType)%> <%=LocalName(parameter.Name)%><%end%>;
|
||||
<%end)%>
|
||||
<%
|
||||
if has_return then
|
||||
%> <%=CsFullTypeName(overload.ReturnType)%> gen_ret = <%
|
||||
end
|
||||
%><%if method.IsStatic then
|
||||
%><%=CsFullTypeName(type).."."..UnK(overload.Name)%><%
|
||||
else
|
||||
%>gen_to_be_invoked.<%=UnK(overload.Name)%><%
|
||||
end%>( <%ForEachCsList(parameters, function(parameter, pi)
|
||||
if pi >= real_param_count then return end
|
||||
if pi ~= 0 then %>, <% end; if parameter.IsOut and parameter.ParameterType.IsByRef then %>out <% elseif parameter.ParameterType.IsByRef then %>ref <% end %><%=LocalName(parameter.Name)%><% end) %> );
|
||||
<%
|
||||
if has_return then
|
||||
%> <%=GetPushStatement(overload.ReturnType, "gen_ret")%>;
|
||||
<%
|
||||
end
|
||||
local in_pos = 0
|
||||
ForEachCsList(parameters, function(parameter, pi)
|
||||
if pi >= real_param_count then return end
|
||||
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
|
||||
in_pos = in_pos + 1
|
||||
end
|
||||
if parameter.ParameterType.IsByRef then
|
||||
%><%=GetPushStatement(parameter.ParameterType:GetElementType(), LocalName(parameter.Name))%>;
|
||||
<%if not parameter.IsOut and parameter.ParameterType.IsByRef and NeedUpdate(parameter.ParameterType) then
|
||||
%><%=GetUpdateStatement(parameter.ParameterType:GetElementType(), in_pos+param_offset, LocalName(parameter.Name))%>;
|
||||
<%end%>
|
||||
<%
|
||||
end
|
||||
end)
|
||||
end
|
||||
%>
|
||||
<%if NeedUpdate(type) and not method.IsStatic then%>
|
||||
<%=GetUpdateStatement(type, 1, "gen_to_be_invoked")%>;
|
||||
<%end%>
|
||||
|
||||
return <%=out_num+(has_return and 1 or 0)%>;
|
||||
}
|
||||
<% end)%>
|
||||
} catch(System.Exception gen_e) {
|
||||
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
||||
}
|
||||
<%if method.Overloads.Count > 1 then%>
|
||||
return LuaAPI.luaL_error(L, "invalid arguments to <%=CsFullTypeName(type)%>.<%=method.Overloads[0].Name%>!");
|
||||
<%end%>
|
||||
}
|
||||
<% end)%>
|
||||
|
||||
|
||||
<%ForEachCsList(getters, function(getter)
|
||||
if getter.IsStatic and getter.ReadOnly then return end --readonly static
|
||||
%>
|
||||
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
||||
static int _g_get_<%=getter.Name%>(RealStatePtr L)
|
||||
{
|
||||
try {
|
||||
<%if AccessorNeedTranslator(getter) then %> ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);<%end%>
|
||||
<%if not getter.IsStatic then%>
|
||||
<%=GetSelfStatement(type)%>;
|
||||
<%=GetPushStatement(getter.Type, "gen_to_be_invoked."..UnK(getter.Name))%>;<% else %> <%=GetPushStatement(getter.Type, CsFullTypeName(type).."."..UnK(getter.Name))%>;<% end%>
|
||||
} catch(System.Exception gen_e) {
|
||||
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
<%end)%>
|
||||
|
||||
<%ForEachCsList(setters, function(setter)
|
||||
local is_struct = IsStruct(setter.Type)
|
||||
%>
|
||||
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
||||
static int _s_set_<%=setter.Name%>(RealStatePtr L)
|
||||
{
|
||||
try {
|
||||
<%if AccessorNeedTranslator(setter) then %>ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);<%end%>
|
||||
<%if not setter.IsStatic then %>
|
||||
<%=GetSelfStatement(type)%>;
|
||||
<%if is_struct then %><%=GetCasterStatement(setter.Type, 2, "gen_value", true)%>;
|
||||
gen_to_be_invoked.<%=UnK(setter.Name)%> = gen_value;<% else
|
||||
%><%=GetCasterStatement(setter.Type, 2, "gen_to_be_invoked." .. UnK(setter.Name))%>;<%end
|
||||
else
|
||||
if is_struct then %><%=GetCasterStatement(setter.Type, 1, "gen_value", true)%>;
|
||||
<%=CsFullTypeName(type)%>.<%=UnK(setter.Name)%> = gen_value;<%else
|
||||
%> <%=GetCasterStatement(setter.Type, 1, CsFullTypeName(type) .."." .. UnK(setter.Name))%>;<%end
|
||||
end%>
|
||||
<%if NeedUpdate(type) and not setter.IsStatic then%>
|
||||
<%=GetUpdateStatement(type, 1, "gen_to_be_invoked")%>;
|
||||
<%end%>
|
||||
} catch(System.Exception gen_e) {
|
||||
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
<%end)%>
|
||||
|
||||
<%ForEachCsList(events, function(event) if not event.IsStatic then %>
|
||||
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
||||
static int _e_<%=event.Name%>(RealStatePtr L)
|
||||
{
|
||||
try {
|
||||
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
||||
int gen_param_count = LuaAPI.lua_gettop(L);
|
||||
<%=GetSelfStatement(type)%>;
|
||||
<%=GetCasterStatement(event.Type, 3, "gen_delegate", true)%>;
|
||||
if (gen_delegate == null) {
|
||||
return LuaAPI.luaL_error(L, "#3 need <%=CsFullTypeName(event.Type)%>!");
|
||||
}
|
||||
|
||||
if (gen_param_count == 3)
|
||||
{
|
||||
<%if event.CanAdd then%>
|
||||
if (LuaAPI.xlua_is_eq_str(L, 2, "+")) {
|
||||
gen_to_be_invoked.<%=UnK(event.Name)%> += gen_delegate;
|
||||
return 0;
|
||||
}
|
||||
<%end%>
|
||||
<%if event.CanRemove then%>
|
||||
if (LuaAPI.xlua_is_eq_str(L, 2, "-")) {
|
||||
gen_to_be_invoked.<%=UnK(event.Name)%> -= gen_delegate;
|
||||
return 0;
|
||||
}
|
||||
<%end%>
|
||||
}
|
||||
} catch(System.Exception gen_e) {
|
||||
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
||||
}
|
||||
LuaAPI.luaL_error(L, "invalid arguments to <%=CsFullTypeName(type)%>.<%=event.Name%>!");
|
||||
return 0;
|
||||
}
|
||||
<%end end)%>
|
||||
|
||||
<%ForEachCsList(events, function(event) if event.IsStatic then %>
|
||||
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
||||
static int _e_<%=event.Name%>(RealStatePtr L)
|
||||
{
|
||||
try {
|
||||
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
||||
int gen_param_count = LuaAPI.lua_gettop(L);
|
||||
<%=GetCasterStatement(event.Type, 2, "gen_delegate", true)%>;
|
||||
if (gen_delegate == null) {
|
||||
return LuaAPI.luaL_error(L, "#2 need <%=CsFullTypeName(event.Type)%>!");
|
||||
}
|
||||
|
||||
<%if event.CanAdd then%>
|
||||
if (gen_param_count == 2 && LuaAPI.xlua_is_eq_str(L, 1, "+")) {
|
||||
<%=CsFullTypeName(type)%>.<%=UnK(event.Name)%> += gen_delegate;
|
||||
return 0;
|
||||
}
|
||||
<%end%>
|
||||
<%if event.CanRemove then%>
|
||||
if (gen_param_count == 2 && LuaAPI.xlua_is_eq_str(L, 1, "-")) {
|
||||
<%=CsFullTypeName(type)%>.<%=UnK(event.Name)%> -= gen_delegate;
|
||||
return 0;
|
||||
}
|
||||
<%end%>
|
||||
} catch(System.Exception gen_e) {
|
||||
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
|
||||
}
|
||||
return LuaAPI.luaL_error(L, "invalid arguments to <%=CsFullTypeName(type)%>.<%=event.Name%>!");
|
||||
}
|
||||
<%end end)%>
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 460ba7dce84f3a54f879d9a3c5d02630
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,517 @@
|
||||
#if USE_UNI_LUA
|
||||
using LuaAPI = UniLua.Lua;
|
||||
using RealStatePtr = UniLua.ILuaState;
|
||||
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
|
||||
#else
|
||||
using LuaAPI = XLua.LuaDLL.Lua;
|
||||
using RealStatePtr = System.IntPtr;
|
||||
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
|
||||
#endif
|
||||
|
||||
using XLua;
|
||||
using System.Collections.Generic;
|
||||
<%ForEachCsList(namespaces, function(namespace)%>using <%=namespace%>;<%end)%>
|
||||
<%
|
||||
require "TemplateCommon"
|
||||
|
||||
local OpNameMap = {
|
||||
op_Addition = "__AddMeta",
|
||||
op_Subtraction = "__SubMeta",
|
||||
op_Multiply = "__MulMeta",
|
||||
op_Division = "__DivMeta",
|
||||
op_Equality = "__EqMeta",
|
||||
op_UnaryNegation = "__UnmMeta",
|
||||
op_LessThan = "__LTMeta",
|
||||
op_LessThanOrEqual = "__LEMeta",
|
||||
op_Modulus = "__ModMeta",
|
||||
op_BitwiseAnd = "__BandMeta",
|
||||
op_BitwiseOr = "__BorMeta",
|
||||
op_ExclusiveOr = "__BxorMeta",
|
||||
op_OnesComplement = "__BnotMeta",
|
||||
op_LeftShift = "__ShlMeta",
|
||||
op_RightShift = "__ShrMeta",
|
||||
}
|
||||
|
||||
local OpCallNameMap = {
|
||||
op_Addition = "+",
|
||||
op_Subtraction = "-",
|
||||
op_Multiply = "*",
|
||||
op_Division = "/",
|
||||
op_Equality = "==",
|
||||
op_UnaryNegation = "-",
|
||||
op_LessThan = "<",
|
||||
op_LessThanOrEqual = "<=",
|
||||
op_Modulus = "%",
|
||||
op_BitwiseAnd = "&",
|
||||
op_BitwiseOr = "|",
|
||||
op_ExclusiveOr = "^",
|
||||
op_OnesComplement = "~",
|
||||
op_LeftShift = "<<",
|
||||
op_RightShift = ">>",
|
||||
}
|
||||
|
||||
local obj_method_count = 0
|
||||
local obj_getter_count = 0
|
||||
local obj_setter_count = 0
|
||||
local meta_func_count = operators.Count
|
||||
local cls_field_count = 1
|
||||
local cls_getter_count = 0
|
||||
local cls_setter_count = 0
|
||||
|
||||
ForEachCsList(methods, function(method)
|
||||
if method.IsStatic then
|
||||
cls_field_count = cls_field_count + 1
|
||||
else
|
||||
obj_method_count = obj_method_count + 1
|
||||
end
|
||||
end)
|
||||
|
||||
ForEachCsList(events, function(event)
|
||||
if event.IsStatic then
|
||||
cls_field_count = cls_field_count + 1
|
||||
else
|
||||
obj_method_count = obj_method_count + 1
|
||||
end
|
||||
end)
|
||||
|
||||
ForEachCsList(getters, function(getter)
|
||||
if getter.IsStatic then
|
||||
if getter.ReadOnly then
|
||||
cls_field_count = cls_field_count + 1
|
||||
else
|
||||
cls_getter_count = cls_getter_count + 1
|
||||
end
|
||||
else
|
||||
obj_getter_count = obj_getter_count + 1
|
||||
end
|
||||
end)
|
||||
|
||||
ForEachCsList(setters, function(setter)
|
||||
if setter.IsStatic then
|
||||
cls_setter_count = cls_setter_count + 1
|
||||
else
|
||||
obj_setter_count = obj_setter_count + 1
|
||||
end
|
||||
end)
|
||||
|
||||
ForEachCsList(lazymembers, function(lazymember)
|
||||
if lazymember.IsStatic == 'true' then
|
||||
if 'CLS_IDX' == lazymember.Index then
|
||||
cls_field_count = cls_field_count + 1
|
||||
elseif 'CLS_GETTER_IDX' == lazymember.Index then
|
||||
cls_getter_count = cls_getter_count + 1
|
||||
elseif 'CLS_SETTER_IDX' == lazymember.Index then
|
||||
cls_setter_count = cls_setter_count + 1
|
||||
end
|
||||
else
|
||||
if 'METHOD_IDX' == lazymember.Index then
|
||||
obj_method_count = obj_method_count + 1
|
||||
elseif 'GETTER_IDX' == lazymember.Index then
|
||||
obj_getter_count = obj_getter_count + 1
|
||||
elseif 'SETTER_IDX' == lazymember.Index then
|
||||
obj_setter_count = obj_setter_count + 1
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
local v_type_name = CSVariableName(type)
|
||||
local generic_arg_list, type_constraints = GenericArgumentList(type)
|
||||
|
||||
%>
|
||||
namespace XLua
|
||||
{
|
||||
public partial class ObjectTranslator
|
||||
{
|
||||
public void __Register<%=v_type_name%><%=generic_arg_list%>(RealStatePtr L) <%=type_constraints%>
|
||||
{
|
||||
System.Type type = typeof(<%=CsFullTypeName(type)%>);
|
||||
Utils.BeginObjectRegister(type, L, this, <%=meta_func_count%>, <%=obj_method_count%>, <%=obj_getter_count%>, <%=obj_setter_count%>);
|
||||
<%ForEachCsList(operators, function(operator)%>Utils.RegisterFunc(L, Utils.OBJ_META_IDX, "<%=(OpNameMap[operator.Name]):gsub('Meta', ''):lower()%>", <%=v_type_name%><%=OpNameMap[operator.Name]%><%=generic_arg_list%>);
|
||||
<%end)%>
|
||||
<%ForEachCsList(methods, function(method) if not method.IsStatic then %>Utils.RegisterFunc(L, Utils.METHOD_IDX, "<%=method.Name%>", <%=v_type_name%>_m_<%=method.Name%><%=generic_arg_list%>);
|
||||
<% end end)%>
|
||||
<%ForEachCsList(events, function(event) if not event.IsStatic then %>Utils.RegisterFunc(L, Utils.METHOD_IDX, "<%=event.Name%>", <%=v_type_name%>_e_<%=event.Name%><%=generic_arg_list%>);
|
||||
<% end end)%>
|
||||
<%ForEachCsList(getters, function(getter) if not getter.IsStatic then %>Utils.RegisterFunc(L, Utils.GETTER_IDX, "<%=getter.Name%>", <%=v_type_name%>_g_get_<%=getter.Name%><%=generic_arg_list%>);
|
||||
<%end end)%>
|
||||
<%ForEachCsList(setters, function(setter) if not setter.IsStatic then %>Utils.RegisterFunc(L, Utils.SETTER_IDX, "<%=setter.Name%>", <%=v_type_name%>_s_set_<%=setter.Name%><%=generic_arg_list%>);
|
||||
<%end end)%>
|
||||
<%ForEachCsList(lazymembers, function(lazymember) if lazymember.IsStatic == 'false' then %>Utils.RegisterLazyFunc(L, Utils.<%=lazymember.Index%>, "<%=lazymember.Name%>", type, <%=lazymember.MemberType%>, <%=lazymember.IsStatic%>);
|
||||
<%end end)%>
|
||||
Utils.EndObjectRegister(type, L, this, <% if type.IsArray or ((indexers.Count or 0) > 0) then %>__CSIndexer<%=v_type_name%><%=generic_arg_list%><%else%>null<%end%>, <%if type.IsArray or ((newindexers.Count or 0) > 0) then%>__NewIndexer<%=v_type_name%><%=generic_arg_list%><%else%>null<%end%>,
|
||||
null, null, null);
|
||||
|
||||
Utils.BeginClassRegister(type, L, __CreateInstance<%=v_type_name%><%=generic_arg_list%>, <%=cls_field_count%>, <%=cls_getter_count%>, <%=cls_setter_count%>);
|
||||
<%ForEachCsList(methods, function(method) if method.IsStatic then %>Utils.RegisterFunc(L, Utils.CLS_IDX, "<%=method.Overloads[0].Name%>", <%=v_type_name%>_m_<%=method.Name%><%=generic_arg_list%>);
|
||||
<% end end)%>
|
||||
<%ForEachCsList(events, function(event) if event.IsStatic then %>Utils.RegisterFunc(L, Utils.CLS_IDX, "<%=event.Name%>", <%=v_type_name%>_e_<%=event.Name%><%=generic_arg_list%>);
|
||||
<% end end)%>
|
||||
<%ForEachCsList(getters, function(getter) if getter.IsStatic and getter.ReadOnly then %>Utils.RegisterObject(L, this, Utils.CLS_IDX, "<%=getter.Name%>", <%=CsFullTypeName(type).."."..getter.Name%>);
|
||||
<%end end)%>
|
||||
<%ForEachCsList(getters, function(getter) if getter.IsStatic and (not getter.ReadOnly) then %>Utils.RegisterFunc(L, Utils.CLS_GETTER_IDX, "<%=getter.Name%>", <%=v_type_name%>_g_get_<%=getter.Name%><%=generic_arg_list%>);
|
||||
<%end end)%>
|
||||
<%ForEachCsList(setters, function(setter) if setter.IsStatic then %>Utils.RegisterFunc(L, Utils.CLS_SETTER_IDX, "<%=setter.Name%>", <%=v_type_name%>_s_set_<%=setter.Name%><%=generic_arg_list%>);
|
||||
<%end end)%>
|
||||
<%ForEachCsList(lazymembers, function(lazymember) if lazymember.IsStatic == 'true' then %>Utils.RegisterLazyFunc(L, Utils.<%=lazymember.Index%>, "<%=lazymember.Name%>", type, <%=lazymember.MemberType%>, <%=lazymember.IsStatic%>);
|
||||
<%end end)%>
|
||||
Utils.EndClassRegister(type, L, this);
|
||||
}
|
||||
|
||||
int __CreateInstance<%=v_type_name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
|
||||
{
|
||||
<%
|
||||
if constructors.Count == 0 and (not type.IsValueType) then
|
||||
%>return LuaAPI.luaL_error(L, "<%=CsFullTypeName(type)%> does not have a constructor!");<%
|
||||
else %>
|
||||
ObjectTranslator translator = this;
|
||||
<%
|
||||
local hasZeroParamsCtor = false
|
||||
ForEachCsList(constructors, function(constructor, ci)
|
||||
local parameters = constructor:GetParameters()
|
||||
if parameters.Length == 0 then
|
||||
hasZeroParamsCtor = true
|
||||
end
|
||||
local def_count = constructor_def_vals[ci]
|
||||
local param_count = parameters.Length
|
||||
local in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)
|
||||
local out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)
|
||||
local real_param_count = param_count - def_count
|
||||
local has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])
|
||||
local in_pos = 0
|
||||
%>if(gen_param_count <%=has_v_params and ">=" or "=="%> <%=in_num + 1 - def_count - (has_v_params and 1 or 0)%><%ForEachCsList(parameters, function(parameter, pi)
|
||||
if pi >= real_param_count then return end
|
||||
local parameterType = parameter.ParameterType
|
||||
if has_v_params and pi == param_count - 1 then parameterType = parameterType:GetElementType() end
|
||||
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then in_pos = in_pos + 1
|
||||
%> && <%=GetCheckStatement(parameterType, in_pos+1, has_v_params and pi == param_count - 1)%><%
|
||||
end
|
||||
end)%>)
|
||||
{
|
||||
<%ForEachCsList(parameters, function(parameter, pi)
|
||||
if pi >= real_param_count then return end
|
||||
%><%=GetCasterStatement(parameter.ParameterType, pi+2, LocalName(parameter.Name), true, has_v_params and pi == param_count - 1)%>;
|
||||
<%end)%>
|
||||
<%=CsFullTypeName(type)%> gen_ret = new <%=CsFullTypeName(type)%>(<%ForEachCsList(parameters, function(parameter, pi) if pi >= real_param_count then return end; if pi ~=0 then %><%=', '%><% end ;if parameter.IsOut and parameter.ParameterType.IsByRef then %>out <% elseif parameter.ParameterType.IsByRef then %>ref <% end %><%=LocalName(parameter.Name)%><% end)%>);
|
||||
<%=GetPushStatement(type, "gen_ret")%>;
|
||||
<%local in_pos = 0
|
||||
ForEachCsList(parameters, function(parameter, pi)
|
||||
if pi >= real_param_count then return end
|
||||
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
|
||||
in_pos = in_pos + 1
|
||||
end
|
||||
if parameter.ParameterType.IsByRef then
|
||||
%><%=GetPushStatement(parameter.ParameterType:GetElementType(), LocalName(parameter.Name))%>;
|
||||
<%if not parameter.IsOut and parameter.ParameterType.IsByRef and NeedUpdate(parameter.ParameterType) then
|
||||
%><%=GetUpdateStatement(parameter.ParameterType:GetElementType(), in_pos+1, LocalName(parameter.Name))%>;
|
||||
<%end%>
|
||||
<%
|
||||
end
|
||||
end)
|
||||
%>
|
||||
return <%=out_num + 1%>;
|
||||
}
|
||||
<%end)
|
||||
if (not hasZeroParamsCtor) and type.IsValueType then
|
||||
%>
|
||||
if (gen_param_count == 1)
|
||||
{
|
||||
<%=GetPushStatement(type, "default(" .. CsFullTypeName(type).. ")")%>;
|
||||
return 1;
|
||||
}
|
||||
<%end%>
|
||||
|
||||
return LuaAPI.luaL_error(L, "invalid arguments to <%=CsFullTypeName(type)%> constructor!");
|
||||
<% end %>
|
||||
}
|
||||
|
||||
<% if type.IsArray or ((indexers.Count or 0) > 0) then %>
|
||||
int __CSIndexer<%=v_type_name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
|
||||
{
|
||||
<%if type.IsArray then %>
|
||||
ObjectTranslator translator = this;
|
||||
if (<%=GetCheckStatement(type, 1)%> && LuaAPI.lua_isnumber(L, 2))
|
||||
{
|
||||
int index = (int)LuaAPI.lua_tonumber(L, 2);
|
||||
<%=GetSelfStatement(type)%>;
|
||||
LuaAPI.lua_pushboolean(L, true);
|
||||
<%=GetPushStatement(type:GetElementType(), "gen_to_be_invoked[index]")%>;
|
||||
return 2;
|
||||
}
|
||||
<%elseif indexers.Count > 0 then
|
||||
%>ObjectTranslator translator = this;
|
||||
<%
|
||||
ForEachCsList(indexers, function(indexer)
|
||||
local paramter = indexer:GetParameters()[0]
|
||||
%>
|
||||
if (<%=GetCheckStatement(type, 1)%> && <%=GetCheckStatement(paramter.ParameterType, 2)%>)
|
||||
{
|
||||
|
||||
<%=GetSelfStatement(type)%>;
|
||||
<%=GetCasterStatement(paramter.ParameterType, 2, "index", true)%>;
|
||||
LuaAPI.lua_pushboolean(L, true);
|
||||
<%=GetPushStatement(indexer.ReturnType, "gen_to_be_invoked[index]")%>;
|
||||
return 2;
|
||||
}
|
||||
<%end)
|
||||
end%>
|
||||
LuaAPI.lua_pushboolean(L, false);
|
||||
return 1;
|
||||
}
|
||||
<% end %>
|
||||
|
||||
<%if type.IsArray or ((newindexers.Count or 0) > 0) then%>
|
||||
int __NewIndexer<%=v_type_name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
|
||||
{
|
||||
<%if type.IsArray or newindexers.Count > 0 then %>ObjectTranslator translator = this;<%end%>
|
||||
<%if type.IsArray then
|
||||
local elementType = type:GetElementType()
|
||||
%>
|
||||
if (<%=GetCheckStatement(type, 1)%> && LuaAPI.lua_isnumber(L, 2) && <%=GetCheckStatement(elementType, 3)%>)
|
||||
{
|
||||
int index = (int)LuaAPI.lua_tonumber(L, 2);
|
||||
<%=GetSelfStatement(type)%>;
|
||||
<%=GetCasterStatement(elementType, 3, "gen_to_be_invoked[index]")%>;
|
||||
LuaAPI.lua_pushboolean(L, true);
|
||||
return 1;
|
||||
}
|
||||
<%elseif newindexers.Count > 0 then%>
|
||||
<%ForEachCsList(newindexers, function(newindexer)
|
||||
local keyType = newindexer:GetParameters()[0].ParameterType
|
||||
local valueType = newindexer:GetParameters()[1].ParameterType
|
||||
%>
|
||||
if (<%=GetCheckStatement(type, 1)%> && <%=GetCheckStatement(keyType, 2)%> && <%=GetCheckStatement(valueType, 3)%>)
|
||||
{
|
||||
|
||||
<%=GetSelfStatement(type)%>;
|
||||
<%=GetCasterStatement(keyType, 2, "key", true)%>;
|
||||
<%if IsStruct(valueType) then%><%=GetCasterStatement(valueType, 3, "gen_value", true)%>;
|
||||
gen_to_be_invoked[key] = gen_value;<%else
|
||||
%><%=GetCasterStatement(valueType, 3, "gen_to_be_invoked[key]")%>;<%end%>
|
||||
LuaAPI.lua_pushboolean(L, true);
|
||||
return 1;
|
||||
}
|
||||
<%end)
|
||||
end%>
|
||||
LuaAPI.lua_pushboolean(L, false);
|
||||
return 1;
|
||||
}
|
||||
<% end %>
|
||||
|
||||
<%ForEachCsList(operators, function(operator) %>
|
||||
int <%=v_type_name%><%=OpNameMap[operator.Name]%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
|
||||
{
|
||||
ObjectTranslator translator = this;
|
||||
<% if operator.Name ~= "op_UnaryNegation" and operator.Name ~= "op_OnesComplement" then
|
||||
ForEachCsList(operator.Overloads, function(overload)
|
||||
local left_param = overload:GetParameters()[0]
|
||||
local right_param = overload:GetParameters()[1]
|
||||
%>
|
||||
if (<%=GetCheckStatement(left_param.ParameterType, 1)%> && <%=GetCheckStatement(right_param.ParameterType, 2)%>)
|
||||
{
|
||||
<%=GetCasterStatement(left_param.ParameterType, 1, "leftside", true)%>;
|
||||
<%=GetCasterStatement(right_param.ParameterType, 2, "rightside", true)%>;
|
||||
|
||||
<%=GetPushStatement(overload.ReturnType, "leftside " .. OpCallNameMap[operator.Name] .. " rightside")%>;
|
||||
|
||||
return 1;
|
||||
}
|
||||
<%end)%>
|
||||
return LuaAPI.luaL_error(L, "invalid arguments to right hand of <%=OpCallNameMap[operator.Name]%> operator, need <%=CsFullTypeName(type)%>!");
|
||||
<%else%>
|
||||
<%=GetCasterStatement(type, 1, "rightside", true)%>;
|
||||
<%=GetPushStatement(operator.Overloads[0].ReturnType, OpCallNameMap[operator.Name] .. " rightside")%>;
|
||||
return 1;
|
||||
<%end%>
|
||||
}
|
||||
<%end)%>
|
||||
|
||||
<%ForEachCsList(methods, function(method)%>
|
||||
int <%=v_type_name%>_m_<%=method.Name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
|
||||
{
|
||||
<%
|
||||
local need_obj = not method.IsStatic
|
||||
if MethodCallNeedTranslator(method) then
|
||||
%>
|
||||
ObjectTranslator translator = this;
|
||||
<%end%>
|
||||
<%if need_obj then%>
|
||||
<%=GetSelfStatement(type)%>;
|
||||
<%end%>
|
||||
<%ForEachCsList(method.Overloads, function(overload, oi)
|
||||
local parameters = MethodParameters(overload)
|
||||
local in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)
|
||||
local param_offset = method.IsStatic and 0 or 1
|
||||
local out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)
|
||||
local in_pos = 0
|
||||
local has_return = (overload.ReturnType.FullName ~= "System.Void")
|
||||
local def_count = method.DefaultValues[oi]
|
||||
local param_count = parameters.Length
|
||||
local real_param_count = param_count - def_count
|
||||
local has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])
|
||||
if method.Overloads.Count > 1 then
|
||||
%>if(gen_param_count <%=has_v_params and ">=" or "=="%> <%=in_num+param_offset-def_count - (has_v_params and 1 or 0)%><%
|
||||
ForEachCsList(parameters, function(parameter, pi)
|
||||
if pi >= real_param_count then return end
|
||||
local parameterType = parameter.ParameterType
|
||||
if has_v_params and pi == param_count - 1 then parameterType = parameterType:GetElementType() end
|
||||
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then in_pos = in_pos + 1;
|
||||
%>&& <%=GetCheckStatement(parameterType , in_pos+param_offset, has_v_params and pi == param_count - 1)%><%
|
||||
end
|
||||
end)%>) <%end%>
|
||||
{
|
||||
<%if overload.Name == "get_Item" and overload.IsSpecialName then
|
||||
local keyType = overload:GetParameters()[0].ParameterType%>
|
||||
<%=GetCasterStatement(keyType, 2, "key", true)%>;
|
||||
<%=GetPushStatement(overload.ReturnType, "gen_to_be_invoked[key]")%>;
|
||||
<%elseif overload.Name == "set_Item" and overload.IsSpecialName then
|
||||
local keyType = overload:GetParameters()[0].ParameterType
|
||||
local valueType = overload:GetParameters()[1].ParameterType%>
|
||||
<%=GetCasterStatement(keyType, 2, "key", true)%>;
|
||||
<%=GetCasterStatement(valueType, 3, "gen_to_be_invoked[key]")%>;
|
||||
<% else
|
||||
in_pos = 0;
|
||||
ForEachCsList(parameters, function(parameter, pi)
|
||||
if pi >= real_param_count then return end
|
||||
%><%if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
|
||||
in_pos = in_pos + 1
|
||||
%><%=GetCasterStatement(parameter.ParameterType, in_pos+param_offset, LocalName(parameter.Name), true, has_v_params and pi == param_count - 1)%><%
|
||||
else%><%=CsFullTypeName(parameter.ParameterType)%> <%=LocalName(parameter.Name)%><%end%>;
|
||||
<%end)%>
|
||||
<%
|
||||
if has_return then
|
||||
%><%=CsFullTypeName(overload.ReturnType)%> gen_ret = <%
|
||||
end
|
||||
%><%if method.IsStatic then
|
||||
%><%=CsFullTypeName(type).."."..UnK(overload.Name)%><%
|
||||
else
|
||||
%>gen_to_be_invoked.<%=UnK(overload.Name)%><%
|
||||
end%>( <%ForEachCsList(parameters, function(parameter, pi)
|
||||
if pi >= real_param_count then return end
|
||||
if pi ~= 0 then %>, <% end; if parameter.IsOut and parameter.ParameterType.IsByRef then %>out <% elseif parameter.ParameterType.IsByRef then %>ref <% end %><%=LocalName(parameter.Name)%><% end) %> );
|
||||
<%
|
||||
if has_return then
|
||||
%><%=GetPushStatement(overload.ReturnType, "gen_ret")%>;
|
||||
<%
|
||||
end
|
||||
local in_pos = 0
|
||||
ForEachCsList(parameters, function(parameter, pi)
|
||||
if pi >= real_param_count then return end
|
||||
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
|
||||
in_pos = in_pos + 1
|
||||
end
|
||||
if parameter.ParameterType.IsByRef then
|
||||
%><%=GetPushStatement(parameter.ParameterType:GetElementType(), LocalName(parameter.Name))%>;
|
||||
<%if not parameter.IsOut and parameter.ParameterType.IsByRef and NeedUpdate(parameter.ParameterType) then
|
||||
%><%=GetUpdateStatement(parameter.ParameterType:GetElementType(), in_pos+param_offset, LocalName(parameter.Name))%>;
|
||||
<%end%>
|
||||
<%
|
||||
end
|
||||
end)
|
||||
end
|
||||
%>
|
||||
<%if NeedUpdate(type) and not method.IsStatic then%>
|
||||
<%=GetUpdateStatement(type, 1, "gen_to_be_invoked")%>;
|
||||
<%end%>
|
||||
|
||||
return <%=out_num+(has_return and 1 or 0)%>;
|
||||
}
|
||||
<% end)%>
|
||||
<%if method.Overloads.Count > 1 then%>
|
||||
return LuaAPI.luaL_error(L, "invalid arguments to <%=CsFullTypeName(type)%>.<%=method.Overloads[0].Name%>!");
|
||||
<%end%>
|
||||
}
|
||||
<% end)%>
|
||||
|
||||
|
||||
<%ForEachCsList(getters, function(getter)
|
||||
if getter.IsStatic and getter.ReadOnly then return end --readonly static
|
||||
%>
|
||||
int <%=v_type_name%>_g_get_<%=getter.Name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
|
||||
{
|
||||
<%if AccessorNeedTranslator(getter) then %>ObjectTranslator translator = this;<%end%>
|
||||
<%if not getter.IsStatic then%>
|
||||
<%=GetSelfStatement(type)%>;
|
||||
<%=GetPushStatement(getter.Type, "gen_to_be_invoked."..UnK(getter.Name))%>;<% else %> <%=GetPushStatement(getter.Type, CsFullTypeName(type).."."..UnK(getter.Name))%>;<% end%>
|
||||
return 1;
|
||||
}
|
||||
<%end)%>
|
||||
|
||||
<%ForEachCsList(setters, function(setter)
|
||||
local is_struct = IsStruct(setter.Type)
|
||||
%>
|
||||
int <%=v_type_name%>_s_set_<%=setter.Name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
|
||||
{
|
||||
<%if AccessorNeedTranslator(setter) then %>ObjectTranslator translator = this;<%end%>
|
||||
<%if not setter.IsStatic then %>
|
||||
<%=GetSelfStatement(type)%>;
|
||||
<%if is_struct then %><%=GetCasterStatement(setter.Type, 2, "gen_value", true)%>;
|
||||
gen_to_be_invoked.<%=UnK(setter.Name)%> = gen_value;<% else
|
||||
%><%=GetCasterStatement(setter.Type, 2, "gen_to_be_invoked." .. UnK(setter.Name))%>;<%end
|
||||
else
|
||||
if is_struct then %><%=GetCasterStatement(setter.Type, 1, "gen_value", true)%>;
|
||||
<%=CsFullTypeName(type)%>.<%=UnK(setter.Name)%> = gen_value;<%else
|
||||
%><%=GetCasterStatement(setter.Type, 1, CsFullTypeName(type) .."." .. UnK(setter.Name))%>;<%end
|
||||
end%>
|
||||
<%if NeedUpdate(type) and not setter.IsStatic then%>
|
||||
<%=GetUpdateStatement(type, 1, "gen_to_be_invoked")%>;
|
||||
<%end%>
|
||||
return 0;
|
||||
}
|
||||
<%end)%>
|
||||
|
||||
<%ForEachCsList(events, function(event) if not event.IsStatic then %>
|
||||
int <%=v_type_name%>_e_<%=event.Name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
|
||||
{
|
||||
ObjectTranslator translator = this;
|
||||
<%=GetSelfStatement(type)%>;
|
||||
<%=GetCasterStatement(event.Type, 3, "gen_delegate", true)%>;
|
||||
if (gen_delegate == null) {
|
||||
return LuaAPI.luaL_error(L, "#3 need <%=CsFullTypeName(event.Type)%>!");
|
||||
}
|
||||
|
||||
if (gen_param_count == 3)
|
||||
{
|
||||
<%if event.CanAdd then%>
|
||||
if (LuaAPI.xlua_is_eq_str(L, 2, "+")) {
|
||||
gen_to_be_invoked.<%=UnK(event.Name)%> += gen_delegate;
|
||||
return 0;
|
||||
}
|
||||
<%end%>
|
||||
<%if event.CanRemove then%>
|
||||
if (LuaAPI.xlua_is_eq_str(L, 2, "-")) {
|
||||
gen_to_be_invoked.<%=UnK(event.Name)%> -= gen_delegate;
|
||||
return 0;
|
||||
}
|
||||
<%end%>
|
||||
}
|
||||
LuaAPI.luaL_error(L, "invalid arguments to <%=CsFullTypeName(type)%>.<%=event.Name%>!");
|
||||
return 0;
|
||||
}
|
||||
<%end end)%>
|
||||
|
||||
<%ForEachCsList(events, function(event) if event.IsStatic then %>
|
||||
int <%=v_type_name%>_e_<%=event.Name%><%=generic_arg_list%>(RealStatePtr L, int gen_param_count) <%=type_constraints%>
|
||||
{
|
||||
ObjectTranslator translator = this;
|
||||
<%=GetCasterStatement(event.Type, 2, "gen_delegate", true)%>;
|
||||
if (gen_delegate == null) {
|
||||
return LuaAPI.luaL_error(L, "#2 need <%=CsFullTypeName(event.Type)%>!");
|
||||
}
|
||||
|
||||
<%if event.CanAdd then%>
|
||||
if (gen_param_count == 2 && LuaAPI.xlua_is_eq_str(L, 1, "+")) {
|
||||
<%=CsFullTypeName(type)%>.<%=UnK(event.Name)%> += gen_delegate;
|
||||
return 0;
|
||||
}
|
||||
<%end%>
|
||||
<%if event.CanRemove then%>
|
||||
if (gen_param_count == 2 && LuaAPI.xlua_is_eq_str(L, 1, "-")) {
|
||||
<%=CsFullTypeName(type)%>.<%=UnK(event.Name)%> -= gen_delegate;
|
||||
return 0;
|
||||
}
|
||||
<%end%>
|
||||
return LuaAPI.luaL_error(L, "invalid arguments to <%=CsFullTypeName(type)%>.<%=event.Name%>!");
|
||||
}
|
||||
<%end end)%>
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e2fe729e6ea01d54abce94149e4545bc
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,104 @@
|
||||
#if USE_UNI_LUA
|
||||
using LuaAPI = UniLua.Lua;
|
||||
using RealStatePtr = UniLua.ILuaState;
|
||||
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
|
||||
#else
|
||||
using LuaAPI = XLua.LuaDLL.Lua;
|
||||
using RealStatePtr = System.IntPtr;
|
||||
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
|
||||
#endif
|
||||
|
||||
using System;
|
||||
<%
|
||||
require "TemplateCommon"
|
||||
%>
|
||||
|
||||
namespace XLua
|
||||
{
|
||||
public partial class DelegateBridge : DelegateBridgeBase
|
||||
{
|
||||
<%
|
||||
ForEachCsList(delegates_groups, function(delegates_group, group_idx)
|
||||
local delegate = delegates_group.Key
|
||||
local parameters = delegate:GetParameters()
|
||||
local in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)
|
||||
local out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)
|
||||
local in_pos = 0
|
||||
local has_return = (delegate.ReturnType.FullName ~= "System.Void")
|
||||
local return_type_name = has_return and CsFullTypeName(delegate.ReturnType) or "void"
|
||||
local out_idx = has_return and 2 or 1
|
||||
if has_return then out_num = out_num + 1 end
|
||||
%>
|
||||
public <%=return_type_name%> __Gen_Delegate_Imp<%=group_idx%>(<%ForEachCsList(parameters, function(parameter, pi)
|
||||
if pi ~= 0 then
|
||||
%>, <%
|
||||
end
|
||||
if parameter.IsOut and parameter.ParameterType.IsByRef then
|
||||
%>out <%
|
||||
elseif parameter.ParameterType.IsByRef then
|
||||
%>ref <%
|
||||
end
|
||||
%><%=CsFullTypeName(parameter.ParameterType)%> p<%=pi%><%
|
||||
end) %>)
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnv.luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
RealStatePtr L = luaEnv.rawL;
|
||||
int errFunc = LuaAPI.pcall_prepare(L, errorFuncRef, luaReference);
|
||||
<%if CallNeedTranslator(delegate, "") then %>ObjectTranslator translator = luaEnv.translator;<%end%>
|
||||
<%
|
||||
local param_count = parameters.Length
|
||||
local has_v_params = param_count > 0 and parameters[param_count - 1].IsParamArray
|
||||
ForEachCsList(parameters, function(parameter, pi)
|
||||
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
|
||||
%><%=GetPushStatement(parameter.ParameterType, 'p' .. pi, has_v_params and pi == param_count - 1)%>;
|
||||
<%
|
||||
end
|
||||
end) %>
|
||||
PCall(L, <%=has_v_params and ((in_num - 1) .. " + (p".. (param_count - 1) .. " == null ? 0 : p" .. (param_count - 1) .. ".Length)" ) or in_num%>, <%=out_num%>, errFunc);
|
||||
|
||||
<%ForEachCsList(parameters, function(parameter, pi)
|
||||
if parameter.IsOut or parameter.ParameterType.IsByRef then
|
||||
%><%=GetCasterStatement(parameter.ParameterType, "errFunc" .. (" + "..out_idx), 'p' .. pi)%>;
|
||||
<%
|
||||
out_idx = out_idx + 1
|
||||
end
|
||||
end) %>
|
||||
<%if has_return then %><%=GetCasterStatement(delegate.ReturnType, "errFunc + 1", "__gen_ret", true)%>;<% end%>
|
||||
LuaAPI.lua_settop(L, errFunc - 1);
|
||||
<%if has_return then %>return __gen_ret;<% end%>
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
<%end)%>
|
||||
|
||||
static DelegateBridge()
|
||||
{
|
||||
Gen_Flag = true;
|
||||
}
|
||||
|
||||
public override Delegate GetDelegateByType(Type type)
|
||||
{
|
||||
<%
|
||||
ForEachCsList(delegates_groups, function(delegates_group, group_idx)
|
||||
ForEachCsList(delegates_group.Value, function(delegate)
|
||||
if delegate.DeclaringType then
|
||||
local delegate_type_name = CsFullTypeName(delegate.DeclaringType)
|
||||
%>
|
||||
if (type == typeof(<%=delegate_type_name%>))
|
||||
{
|
||||
return new <%=delegate_type_name%>(__Gen_Delegate_Imp<%=group_idx%>);
|
||||
}
|
||||
<%
|
||||
end
|
||||
end)
|
||||
end)
|
||||
%>
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: db09506e3ebf97b4f89bba86e5b0e1d2
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,128 @@
|
||||
#if USE_UNI_LUA
|
||||
using LuaAPI = UniLua.Lua;
|
||||
using RealStatePtr = UniLua.ILuaState;
|
||||
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
|
||||
#else
|
||||
using LuaAPI = XLua.LuaDLL.Lua;
|
||||
using RealStatePtr = System.IntPtr;
|
||||
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
|
||||
#endif
|
||||
|
||||
using XLua;
|
||||
using System.Collections.Generic;
|
||||
<%
|
||||
require "TemplateCommon"
|
||||
|
||||
local parameters = delegate:GetParameters()
|
||||
local in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)
|
||||
local out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)
|
||||
local in_pos = 0
|
||||
local has_return = (delegate.ReturnType.Name ~= "Void")
|
||||
%>
|
||||
|
||||
namespace XLua.CSObjectWrap
|
||||
{
|
||||
using Utils = XLua.Utils;
|
||||
public class <%=CSVariableName(type)%>Wrap
|
||||
{
|
||||
public static void __Register(RealStatePtr L)
|
||||
{
|
||||
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
||||
Utils.BeginObjectRegister(typeof(<%=CsFullTypeName(type)%>), L, translator, 0, 0, 0, 0);
|
||||
Utils.EndObjectRegister(typeof(<%=CsFullTypeName(type)%>), L, translator, null, null, null, null, null);
|
||||
|
||||
Utils.BeginClassRegister(typeof(<%=CsFullTypeName(type)%>), L, null, 1, 0, 0);
|
||||
Utils.EndClassRegister(typeof(<%=CsFullTypeName(type)%>), L, translator);
|
||||
}
|
||||
|
||||
static Dictionary<string, LuaCSFunction> __MetaFucntions_Dic = new Dictionary<string, LuaCSFunction>(){
|
||||
{"__call", __CallMeta},
|
||||
{"__add", __AddMeta},
|
||||
{"__sub", __SubMeta},
|
||||
};
|
||||
|
||||
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
||||
static int __CallMeta(RealStatePtr L)
|
||||
{
|
||||
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
||||
try {
|
||||
if(LuaAPI.lua_gettop(L) == <%=in_num+1%> && <%=GetCheckStatement(type, 1)%><%
|
||||
ForEachCsList(parameters, function(parameter)
|
||||
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then in_pos = in_pos + 1;
|
||||
%>&& <%=GetCheckStatement(parameter.ParameterType, in_pos+1)%><%
|
||||
end
|
||||
end)%>)
|
||||
{
|
||||
<%
|
||||
in_pos = 0;
|
||||
ForEachCsList(parameters, function(parameter)
|
||||
%><%
|
||||
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
|
||||
in_pos = in_pos + 1
|
||||
%><%=GetCasterStatement(parameter.ParameterType, in_pos+1, parameter.Name, true)%><%
|
||||
else%><%=CsFullTypeName(parameter.ParameterType)%> <%=parameter.Name%><%end%>;
|
||||
<%end)%>
|
||||
<%=GetSelfStatement(type)%>;
|
||||
|
||||
<%
|
||||
if has_return then
|
||||
%> <%=CsFullTypeName(delegate.ReturnType)%> __cl_gen_ret = <%
|
||||
end
|
||||
%> __cl_gen_to_be_invoked( <%ForEachCsList(parameters, function(parameter, pi) if pi ~= 0 then %>, <% end; if parameter.IsOut then %>out <% elseif parameter.ParameterType.IsByRef then %>ref <% end %><%=parameter.Name%><% end) %> );
|
||||
<%
|
||||
if has_return then
|
||||
%> <%=GetPushStatement(delegate.ReturnType, "__cl_gen_ret")%>;
|
||||
<%
|
||||
end
|
||||
local in_pos = 0
|
||||
ForEachCsList(parameters, function(parameter)
|
||||
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
|
||||
in_pos = in_pos + 1
|
||||
end
|
||||
if parameter.IsOut or parameter.ParameterType.IsByRef then
|
||||
%><%=GetPushStatement(parameter.ParameterType:GetElementType(), parameter.Name)%>;
|
||||
<%if not parameter.IsOut and parameter.ParameterType.IsByRef and NeedUpdate(parameter.ParameterType) then
|
||||
%><%=GetUpdateStatement(parameter.ParameterType:GetElementType(), in_pos+param_offset, parameter.Name)%>;
|
||||
<%end%>
|
||||
<%
|
||||
end
|
||||
end)
|
||||
%>
|
||||
|
||||
return <%=out_num+(has_return and 1 or 0)%>;
|
||||
}
|
||||
} catch(System.Exception __gen_e) {
|
||||
return LuaAPI.luaL_error(L, "c# exception:" + __gen_e);
|
||||
}
|
||||
return LuaAPI.luaL_error(L, "invalid arguments to Delegate <%=CsFullTypeName(type)%>!");
|
||||
}
|
||||
|
||||
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
||||
static int __AddMeta(RealStatePtr L)
|
||||
{
|
||||
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
||||
try {
|
||||
<%=GetCasterStatement(type, 1, "leftside", true)%>;
|
||||
<%=GetCasterStatement(type, 2, "rightside", true)%>;
|
||||
<%=GetPushStatement(type, "leftside + rightside")%>;
|
||||
return 1;
|
||||
} catch(System.Exception __gen_e) {
|
||||
return LuaAPI.luaL_error(L, "c# exception:" + __gen_e);
|
||||
}
|
||||
}
|
||||
|
||||
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
||||
static int __SubMeta(RealStatePtr L)
|
||||
{
|
||||
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
||||
try {
|
||||
<%=GetCasterStatement(type, 1, "leftside", true)%>;
|
||||
<%=GetCasterStatement(type, 2, "rightside", true)%>;
|
||||
<%=GetPushStatement(type, "leftside - rightside")%>;
|
||||
return 1;
|
||||
} catch(System.Exception __gen_e) {
|
||||
return LuaAPI.luaL_error(L, "c# exception:" + __gen_e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2414baa411b1d0b43b25ef26effb18e4
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,102 @@
|
||||
#if USE_UNI_LUA
|
||||
using LuaAPI = UniLua.Lua;
|
||||
using RealStatePtr = UniLua.ILuaState;
|
||||
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
|
||||
#else
|
||||
using LuaAPI = XLua.LuaDLL.Lua;
|
||||
using RealStatePtr = System.IntPtr;
|
||||
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
|
||||
#endif
|
||||
|
||||
using XLua;
|
||||
using System.Collections.Generic;
|
||||
<%
|
||||
require "TemplateCommon"
|
||||
local enum_or_op = debug.getmetatable(CS.System.Reflection.BindingFlags.Public).__bor
|
||||
%>
|
||||
|
||||
namespace XLua.CSObjectWrap
|
||||
{
|
||||
using Utils = XLua.Utils;
|
||||
<%ForEachCsList(types, function(type)
|
||||
local fields = type2fields and type2fields[type] or type:GetFields(enum_or_op(CS.System.Reflection.BindingFlags.Public, CS.System.Reflection.BindingFlags.Static))
|
||||
local fields_to_gen = {}
|
||||
ForEachCsList(fields, function(field)
|
||||
if field.Name ~= "value__" and not IsObsolute(field) then
|
||||
table.insert(fields_to_gen, field)
|
||||
end
|
||||
end)
|
||||
%>
|
||||
public class <%=CSVariableName(type)%>Wrap
|
||||
{
|
||||
public static void __Register(RealStatePtr L)
|
||||
{
|
||||
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
||||
Utils.BeginObjectRegister(typeof(<%=CsFullTypeName(type)%>), L, translator, 0, 0, 0, 0);
|
||||
Utils.EndObjectRegister(typeof(<%=CsFullTypeName(type)%>), L, translator, null, null, null, null, null);
|
||||
|
||||
Utils.BeginClassRegister(typeof(<%=CsFullTypeName(type)%>), L, null, <%=fields.Length + 1%>, 0, 0);
|
||||
<%if #fields_to_gen <= 20 then%>
|
||||
<% ForEachCsList(fields, function(field)
|
||||
if field.Name == "value__" or IsObsolute(field) then return end
|
||||
%>
|
||||
Utils.RegisterObject(L, translator, Utils.CLS_IDX, "<%=field.Name%>", <%=CsFullTypeName(type)%>.<%=UnK(field.Name)%>);
|
||||
<%end)%>
|
||||
<%else%>
|
||||
Utils.RegisterEnumType(L, typeof(<%=CsFullTypeName(type)%>));
|
||||
<%end%>
|
||||
Utils.RegisterFunc(L, Utils.CLS_IDX, "__CastFrom", __CastFrom);
|
||||
|
||||
Utils.EndClassRegister(typeof(<%=CsFullTypeName(type)%>), L, translator);
|
||||
}
|
||||
|
||||
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
|
||||
static int __CastFrom(RealStatePtr L)
|
||||
{
|
||||
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
|
||||
LuaTypes lua_type = LuaAPI.lua_type(L, 1);
|
||||
if (lua_type == LuaTypes.LUA_TNUMBER)
|
||||
{
|
||||
translator.Push<%=CSVariableName(type)%>(L, (<%=CsFullTypeName(type)%>)LuaAPI.xlua_tointeger(L, 1));
|
||||
}
|
||||
<%if #fields_to_gen > 0 then%>
|
||||
else if(lua_type == LuaTypes.LUA_TSTRING)
|
||||
{
|
||||
<%if #fields_to_gen <= 20 then%>
|
||||
<%
|
||||
local is_first = true
|
||||
ForEachCsList(fields, function(field, i)
|
||||
if field.Name == "value__" or IsObsolute(field) then return end
|
||||
%><%=(is_first and "" or "else ")%>if (LuaAPI.xlua_is_eq_str(L, 1, "<%=field.Name%>"))
|
||||
{
|
||||
translator.Push<%=CSVariableName(type)%>(L, <%=CsFullTypeName(type)%>.<%=UnK(field.Name)%>);
|
||||
}
|
||||
<%
|
||||
is_first = false
|
||||
end)
|
||||
%>else
|
||||
{
|
||||
return LuaAPI.luaL_error(L, "invalid string for <%=CsFullTypeName(type)%>!");
|
||||
}
|
||||
<%else%>
|
||||
try
|
||||
{
|
||||
translator.TranslateToEnumToTop(L, typeof(<%=CsFullTypeName(type)%>), 1);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
return LuaAPI.luaL_error(L, "cast to " + typeof(<%=CsFullTypeName(type)%>) + " exception:" + e);
|
||||
}
|
||||
<%end%>
|
||||
}
|
||||
<%end%>
|
||||
else
|
||||
{
|
||||
return LuaAPI.luaL_error(L, "invalid lua type for <%=CsFullTypeName(type)%>! Expect number or string, got + " + lua_type);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
<%end)%>
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea0bcef8245ac014192198851b00e35f
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,99 @@
|
||||
#if USE_UNI_LUA
|
||||
using LuaAPI = UniLua.Lua;
|
||||
using RealStatePtr = UniLua.ILuaState;
|
||||
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
|
||||
#else
|
||||
using LuaAPI = XLua.LuaDLL.Lua;
|
||||
using RealStatePtr = System.IntPtr;
|
||||
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
|
||||
#endif
|
||||
|
||||
using XLua;
|
||||
using System.Collections.Generic;
|
||||
<%
|
||||
require "TemplateCommon"
|
||||
local enum_or_op = debug.getmetatable(CS.System.Reflection.BindingFlags.Public).__bor
|
||||
%>
|
||||
|
||||
namespace XLua
|
||||
{
|
||||
public partial class ObjectTranslator
|
||||
{
|
||||
<%ForEachCsList(types, function(type)
|
||||
local fields = type2fields and type2fields[type] or type:GetFields(enum_or_op(CS.System.Reflection.BindingFlags.Public, CS.System.Reflection.BindingFlags.Static))
|
||||
local fields_to_gen = {}
|
||||
ForEachCsList(fields, function(field)
|
||||
if field.Name ~= "value__" and not IsObsolute(field) then
|
||||
table.insert(fields_to_gen, field)
|
||||
end
|
||||
end)
|
||||
local v_type_name = CSVariableName(type)
|
||||
%>
|
||||
public void __Register<%=v_type_name%>(RealStatePtr L)
|
||||
{
|
||||
Utils.BeginObjectRegister(typeof(<%=CsFullTypeName(type)%>), L, this, 0, 0, 0, 0);
|
||||
Utils.EndObjectRegister(typeof(<%=CsFullTypeName(type)%>), L, this, null, null, null, null, null);
|
||||
|
||||
Utils.BeginClassRegister(typeof(<%=CsFullTypeName(type)%>), L, null, <%=fields.Length + 1%>, 0, 0);
|
||||
<%if #fields_to_gen <= 20 then%>
|
||||
<% ForEachCsList(fields, function(field)
|
||||
if field.Name == "value__" or IsObsolute(field) then return end
|
||||
%>
|
||||
Utils.RegisterObject(L, this, Utils.CLS_IDX, "<%=field.Name%>", <%=CsFullTypeName(type)%>.<%=UnK(field.Name)%>);
|
||||
<%end)%>
|
||||
<%else%>
|
||||
Utils.RegisterEnumType(L, typeof(<%=CsFullTypeName(type)%>));
|
||||
<%end%>
|
||||
Utils.RegisterFunc(L, Utils.CLS_IDX, "__CastFrom", __CastFrom<%=v_type_name%>);
|
||||
|
||||
Utils.EndClassRegister(typeof(<%=CsFullTypeName(type)%>), L, this);
|
||||
}
|
||||
|
||||
int __CastFrom<%=v_type_name%>(RealStatePtr L, int __gen_top)
|
||||
{
|
||||
LuaTypes lua_type = LuaAPI.lua_type(L, 1);
|
||||
if (lua_type == LuaTypes.LUA_TNUMBER)
|
||||
{
|
||||
Push<%=v_type_name%>(L, (<%=CsFullTypeName(type)%>)LuaAPI.xlua_tointeger(L, 1));
|
||||
}
|
||||
<%if #fields_to_gen > 0 then%>
|
||||
else if(lua_type == LuaTypes.LUA_TSTRING)
|
||||
{
|
||||
<%if #fields_to_gen <= 20 then%>
|
||||
<%
|
||||
local is_first = true
|
||||
ForEachCsList(fields, function(field, i)
|
||||
if field.Name == "value__" or IsObsolute(field) then return end
|
||||
%><%=(is_first and "" or "else ")%>if (LuaAPI.xlua_is_eq_str(L, 1, "<%=field.Name%>"))
|
||||
{
|
||||
Push<%=v_type_name%>(L, <%=CsFullTypeName(type)%>.<%=UnK(field.Name)%>);
|
||||
}
|
||||
<%
|
||||
is_first = false
|
||||
end)
|
||||
%>else
|
||||
{
|
||||
return LuaAPI.luaL_error(L, "invalid string for <%=CsFullTypeName(type)%>!");
|
||||
}
|
||||
<%else%>
|
||||
try
|
||||
{
|
||||
TranslateToEnumToTop(L, typeof(<%=CsFullTypeName(type)%>), 1);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
return LuaAPI.luaL_error(L, "cast to " + typeof(<%=CsFullTypeName(type)%>) + " exception:" + e);
|
||||
}
|
||||
<%end%>
|
||||
}
|
||||
<%end%>
|
||||
else
|
||||
{
|
||||
return LuaAPI.luaL_error(L, "invalid lua type for <%=CsFullTypeName(type)%>! Expect number or string, got + " + lua_type);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
<%end)%>
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a04f4c510c2c4a84aab06f3dacb7e325
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,385 @@
|
||||
#if USE_UNI_LUA
|
||||
using LuaAPI = UniLua.Lua;
|
||||
using RealStatePtr = UniLua.ILuaState;
|
||||
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
|
||||
#else
|
||||
using LuaAPI = XLua.LuaDLL.Lua;
|
||||
using RealStatePtr = System.IntPtr;
|
||||
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
|
||||
#endif
|
||||
|
||||
using XLua;
|
||||
using System;
|
||||
<%
|
||||
require "TemplateCommon"
|
||||
|
||||
%>
|
||||
|
||||
namespace XLua.CSObjectWrap
|
||||
{
|
||||
public class <%=CSVariableName(type)%>Bridge : LuaBase, <%=CsFullTypeName(type)%>
|
||||
{
|
||||
public static LuaBase __Create(int reference, LuaEnv luaenv)
|
||||
{
|
||||
return new <%=CSVariableName(type)%>Bridge(reference, luaenv);
|
||||
}
|
||||
|
||||
public <%=CSVariableName(type)%>Bridge(int reference, LuaEnv luaenv) : base(reference, luaenv)
|
||||
{
|
||||
}
|
||||
|
||||
<%
|
||||
ForEachCsList(methods, function(method)
|
||||
local parameters = method:GetParameters()
|
||||
local in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)
|
||||
local out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)
|
||||
local in_pos = 0
|
||||
local has_return = (method.ReturnType.FullName ~= "System.Void")
|
||||
local return_type_name = has_return and CsFullTypeName(method.ReturnType) or "void"
|
||||
local out_idx = has_return and 2 or 1
|
||||
if has_return then out_num = out_num + 1 end
|
||||
%>
|
||||
<%=return_type_name%> <%=CsFullTypeName(method.DeclaringType)%>.<%=method.Name%>(<%ForEachCsList(parameters, function(parameter, pi)
|
||||
if pi ~= 0 then
|
||||
%>, <%
|
||||
end
|
||||
if parameter.IsOut and parameter.ParameterType.IsByRef then
|
||||
%>out <%
|
||||
elseif parameter.ParameterType.IsByRef then
|
||||
%>ref <%
|
||||
end
|
||||
%><%=CsFullTypeName(parameter.ParameterType)%> <%=parameter.Name%><%
|
||||
end) %>)
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnv.luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
RealStatePtr L = luaEnv.L;
|
||||
int err_func = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
|
||||
<%if CallNeedTranslator(method, "") then %>ObjectTranslator translator = luaEnv.translator;<%end%>
|
||||
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
LuaAPI.xlua_pushasciistring(L, "<%=method.Name%>");
|
||||
if (0 != LuaAPI.xlua_pgettable(L, -2))
|
||||
{
|
||||
luaEnv.ThrowExceptionFromError(err_func - 1);
|
||||
}
|
||||
if(!LuaAPI.lua_isfunction(L, -1))
|
||||
{
|
||||
LuaAPI.xlua_pushasciistring(L, "no such function <%=method.Name%>");
|
||||
luaEnv.ThrowExceptionFromError(err_func - 1);
|
||||
}
|
||||
LuaAPI.lua_pushvalue(L, -2);
|
||||
LuaAPI.lua_remove(L, -3);
|
||||
<%
|
||||
local param_count = parameters.Length
|
||||
local has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])
|
||||
|
||||
ForEachCsList(parameters, function(parameter, pi)
|
||||
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
|
||||
%><%=GetPushStatement(parameter.ParameterType, parameter.Name, has_v_params and pi == param_count - 1)%>;
|
||||
<%
|
||||
end
|
||||
end) %>
|
||||
int __gen_error = LuaAPI.lua_pcall(L, <%=has_v_params and ((in_num) .. " + (".. parameters[param_count - 1].Name .. " == null ? 0 : " .. parameters[param_count - 1].Name .. ".Length)" ) or (in_num + 1)%>, <%=out_num%>, err_func);
|
||||
if (__gen_error != 0)
|
||||
luaEnv.ThrowExceptionFromError(err_func - 1);
|
||||
|
||||
<%ForEachCsList(parameters, function(parameter)
|
||||
if parameter.IsOut or parameter.ParameterType.IsByRef then
|
||||
%><%=GetCasterStatement(parameter.ParameterType, "err_func" .. (" + "..out_idx), parameter.Name)%>;
|
||||
<%
|
||||
out_idx = out_idx + 1
|
||||
end
|
||||
end) %>
|
||||
<%if has_return then %><%=GetCasterStatement(method.ReturnType, "err_func + 1", "__gen_ret", true)%>;<% end%>
|
||||
LuaAPI.lua_settop(L, err_func - 1);
|
||||
<%if has_return then %>return __gen_ret;<% end%>
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
<%end)%>
|
||||
|
||||
<%
|
||||
ForEachCsList(propertys, function(property)
|
||||
%>
|
||||
<%=CsFullTypeName(property.PropertyType)%> <%=CsFullTypeName(property.DeclaringType)%>.<%=property.Name%>
|
||||
{
|
||||
<%if property.CanRead then%>
|
||||
get
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnv.luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
RealStatePtr L = luaEnv.L;
|
||||
int oldTop = LuaAPI.lua_gettop(L);
|
||||
<%if not JustLuaType(property.PropertyType) then %>ObjectTranslator translator = luaEnv.translator;<%end%>
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
LuaAPI.xlua_pushasciistring(L, "<%=property.Name%>");
|
||||
if (0 != LuaAPI.xlua_pgettable(L, -2))
|
||||
{
|
||||
luaEnv.ThrowExceptionFromError(oldTop);
|
||||
}
|
||||
<%=GetCasterStatement(property.PropertyType, "-1", "__gen_ret", true)%>;
|
||||
LuaAPI.lua_pop(L, 2);
|
||||
return __gen_ret;
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
<%end%>
|
||||
<%if property.CanWrite then%>
|
||||
set
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnv.luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
RealStatePtr L = luaEnv.L;
|
||||
int oldTop = LuaAPI.lua_gettop(L);
|
||||
<%if not JustLuaType(property.PropertyType) then %>ObjectTranslator translator = luaEnv.translator;<%end%>
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
LuaAPI.xlua_pushasciistring(L, "<%=property.Name%>");
|
||||
<%=GetPushStatement(property.PropertyType, "value")%>;
|
||||
if (0 != LuaAPI.xlua_psettable(L, -3))
|
||||
{
|
||||
luaEnv.ThrowExceptionFromError(oldTop);
|
||||
}
|
||||
LuaAPI.lua_pop(L, 1);
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
<%end%>
|
||||
}
|
||||
<%end)%>
|
||||
|
||||
<%ForEachCsList(events, function(event) %>
|
||||
event <%=CsFullTypeName(event.EventHandlerType)%> <%=CsFullTypeName(event.DeclaringType)%>.<%=event.Name%>
|
||||
{<%local parameters = event:GetAddMethod():GetParameters()%>
|
||||
add
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnv.luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
RealStatePtr L = luaEnv.L;
|
||||
int err_func = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
|
||||
<%if CallNeedTranslator(event:GetAddMethod(), "") then %>ObjectTranslator translator = luaEnv.translator;<%end%>
|
||||
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
LuaAPI.xlua_pushasciistring(L, "add_<%=event.Name%>");
|
||||
if (0 != LuaAPI.xlua_pgettable(L, -2))
|
||||
{
|
||||
luaEnv.ThrowExceptionFromError(err_func - 1);
|
||||
}
|
||||
if(!LuaAPI.lua_isfunction(L, -1))
|
||||
{
|
||||
LuaAPI.xlua_pushasciistring(L, "no such function add_<%=event.Name%>");
|
||||
luaEnv.ThrowExceptionFromError(err_func - 1);
|
||||
}
|
||||
LuaAPI.lua_pushvalue(L, -2);
|
||||
LuaAPI.lua_remove(L, -3);
|
||||
<%
|
||||
local param_count = parameters.Length
|
||||
local has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])
|
||||
|
||||
ForEachCsList(parameters, function(parameter, pi)
|
||||
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
|
||||
%><%=GetPushStatement(parameter.ParameterType, parameter.Name, has_v_params and pi == param_count - 1)%>;
|
||||
<%
|
||||
end
|
||||
end) %>
|
||||
int __gen_error = LuaAPI.lua_pcall(L, 2, 0, err_func);
|
||||
if (__gen_error != 0)
|
||||
luaEnv.ThrowExceptionFromError(err_func - 1);
|
||||
|
||||
LuaAPI.lua_settop(L, err_func - 1);
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
remove
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnv.luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
RealStatePtr L = luaEnv.L;
|
||||
int err_func = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
|
||||
<%if CallNeedTranslator(event:GetRemoveMethod(), "") then %>ObjectTranslator translator = luaEnv.translator;<%end%>
|
||||
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
LuaAPI.xlua_pushasciistring(L, "remove_<%=event.Name%>");
|
||||
if (0 != LuaAPI.xlua_pgettable(L, -2))
|
||||
{
|
||||
luaEnv.ThrowExceptionFromError(err_func - 1);
|
||||
}
|
||||
if(!LuaAPI.lua_isfunction(L, -1))
|
||||
{
|
||||
LuaAPI.xlua_pushasciistring(L, "no such function remove_<%=event.Name%>");
|
||||
luaEnv.ThrowExceptionFromError(err_func - 1);
|
||||
}
|
||||
LuaAPI.lua_pushvalue(L, -2);
|
||||
LuaAPI.lua_remove(L, -3);
|
||||
<%
|
||||
local param_count = parameters.Length
|
||||
local has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])
|
||||
|
||||
ForEachCsList(parameters, function(parameter, pi)
|
||||
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
|
||||
%><%=GetPushStatement(parameter.ParameterType, parameter.Name, has_v_params and pi == param_count - 1)%>;
|
||||
<%
|
||||
end
|
||||
end) %>
|
||||
int __gen_error = LuaAPI.lua_pcall(L, 2, 0, err_func);
|
||||
if (__gen_error != 0)
|
||||
luaEnv.ThrowExceptionFromError(err_func - 1);
|
||||
|
||||
LuaAPI.lua_settop(L, err_func - 1);
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
<%end)%>
|
||||
|
||||
<%ForEachCsList(indexers, function(indexer)
|
||||
local ptype = (indexer:GetGetMethod() or indexer:GetSetMethod()):GetParameters()[0].ParameterType
|
||||
local pname = (indexer:GetGetMethod() or indexer:GetSetMethod()):GetParameters()[0].Name
|
||||
%>
|
||||
<%=CsFullTypeName(indexer.PropertyType)%> <%=CsFullTypeName(indexer.DeclaringType)%>.this[<%=CsFullTypeName(ptype)%> <%=pname%>]
|
||||
{<%if indexer:GetGetMethod() then
|
||||
local method = indexer:GetGetMethod()
|
||||
local parameters = method:GetParameters()
|
||||
local in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)
|
||||
local out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)
|
||||
local in_pos = 0
|
||||
local has_return = (method.ReturnType.FullName ~= "System.Void")
|
||||
local return_type_name = has_return and CsFullTypeName(method.ReturnType) or "void"
|
||||
local out_idx = has_return and 2 or 1
|
||||
if has_return then out_num = out_num + 1 end
|
||||
%>
|
||||
get
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnv.luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
RealStatePtr L = luaEnv.L;
|
||||
int err_func = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
|
||||
<%if CallNeedTranslator(method, "") then %>ObjectTranslator translator = luaEnv.translator;<%end%>
|
||||
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
LuaAPI.xlua_pushasciistring(L, "<%=method.Name%>");
|
||||
if (0 != LuaAPI.xlua_pgettable(L, -2))
|
||||
{
|
||||
luaEnv.ThrowExceptionFromError(err_func - 1);
|
||||
}
|
||||
if(!LuaAPI.lua_isfunction(L, -1))
|
||||
{
|
||||
LuaAPI.xlua_pushasciistring(L, "no such function <%=method.Name%>");
|
||||
luaEnv.ThrowExceptionFromError(err_func - 1);
|
||||
}
|
||||
LuaAPI.lua_pushvalue(L, -2);
|
||||
LuaAPI.lua_remove(L, -3);
|
||||
<%
|
||||
local param_count = parameters.Length
|
||||
local has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])
|
||||
|
||||
ForEachCsList(parameters, function(parameter, pi)
|
||||
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
|
||||
%><%=GetPushStatement(parameter.ParameterType, parameter.Name, has_v_params and pi == param_count - 1)%>;
|
||||
<%
|
||||
end
|
||||
end) %>
|
||||
int __gen_error = LuaAPI.lua_pcall(L, <%=has_v_params and ((in_num) .. " + " .. parameters[param_count - 1].Name .. ".Length" ) or (in_num + 1)%>, <%=out_num%>, err_func);
|
||||
if (__gen_error != 0)
|
||||
luaEnv.ThrowExceptionFromError(err_func - 1);
|
||||
|
||||
<%ForEachCsList(parameters, function(parameter)
|
||||
if parameter.IsOut or parameter.ParameterType.IsByRef then
|
||||
%><%=GetCasterStatement(parameter.ParameterType, "err_func" .. (" + "..out_idx), parameter.Name)%>;
|
||||
<%
|
||||
out_idx = out_idx + 1
|
||||
end
|
||||
end) %>
|
||||
<%if has_return then %><%=GetCasterStatement(method.ReturnType, "err_func + 1", "__gen_ret", true)%>;<% end%>
|
||||
LuaAPI.lua_settop(L, err_func - 1);
|
||||
<%if has_return then %>return __gen_ret;<% end%>
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
<%end%>
|
||||
<%if indexer:GetSetMethod() then
|
||||
local method = indexer:GetSetMethod()
|
||||
local parameters = method:GetParameters()
|
||||
local in_num = CalcCsList(parameters, function(p) return not (p.IsOut and p.ParameterType.IsByRef) end)
|
||||
local out_num = CalcCsList(parameters, function(p) return p.IsOut or p.ParameterType.IsByRef end)
|
||||
local in_pos = 0
|
||||
local has_return = (method.ReturnType.FullName ~= "System.Void")
|
||||
local return_type_name = has_return and CsFullTypeName(method.ReturnType) or "void"
|
||||
local out_idx = has_return and 2 or 1
|
||||
if has_return then out_num = out_num + 1 end
|
||||
%>
|
||||
set
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnv.luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
RealStatePtr L = luaEnv.L;
|
||||
int err_func = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
|
||||
<%if CallNeedTranslator(method, "") then %>ObjectTranslator translator = luaEnv.translator;<%end%>
|
||||
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
LuaAPI.xlua_pushasciistring(L, "<%=method.Name%>");
|
||||
if (0 != LuaAPI.xlua_pgettable(L, -2))
|
||||
{
|
||||
luaEnv.ThrowExceptionFromError(err_func - 1);
|
||||
}
|
||||
if(!LuaAPI.lua_isfunction(L, -1))
|
||||
{
|
||||
LuaAPI.xlua_pushasciistring(L, "no such function <%=method.Name%>");
|
||||
luaEnv.ThrowExceptionFromError(err_func - 1);
|
||||
}
|
||||
LuaAPI.lua_pushvalue(L, -2);
|
||||
LuaAPI.lua_remove(L, -3);
|
||||
<%
|
||||
local param_count = parameters.Length
|
||||
local has_v_params = param_count > 0 and IsParams(parameters[param_count - 1])
|
||||
|
||||
ForEachCsList(parameters, function(parameter, pi)
|
||||
if not (parameter.IsOut and parameter.ParameterType.IsByRef) then
|
||||
%><%=GetPushStatement(parameter.ParameterType, parameter.Name, has_v_params and pi == param_count - 1)%>;
|
||||
<%
|
||||
end
|
||||
end) %>
|
||||
int __gen_error = LuaAPI.lua_pcall(L, <%=has_v_params and ((in_num) .. " + " .. parameters[param_count - 1].Name .. ".Length" ) or (in_num + 1)%>, <%=out_num%>, err_func);
|
||||
if (__gen_error != 0)
|
||||
luaEnv.ThrowExceptionFromError(err_func - 1);
|
||||
|
||||
<%ForEachCsList(parameters, function(parameter)
|
||||
if parameter.IsOut or parameter.ParameterType.IsByRef then
|
||||
%><%=GetCasterStatement(parameter.ParameterType, "err_func" .. (" + "..out_idx), parameter.Name)%>;
|
||||
<%
|
||||
out_idx = out_idx + 1
|
||||
end
|
||||
end) %>
|
||||
<%if has_return then %><%=GetCasterStatement(method.ReturnType, "err_func + 1", "__gen_ret", true)%>;<% end%>
|
||||
LuaAPI.lua_settop(L, err_func - 1);
|
||||
<%if has_return then %>return __gen_ret;<% end%>
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
<%end%>
|
||||
}
|
||||
<%end)%>
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab2e037c6ce86fe4397f6902cb8daeae
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,140 @@
|
||||
#if USE_UNI_LUA
|
||||
using LuaAPI = UniLua.Lua;
|
||||
using RealStatePtr = UniLua.ILuaState;
|
||||
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
|
||||
#else
|
||||
using LuaAPI = XLua.LuaDLL.Lua;
|
||||
using RealStatePtr = System.IntPtr;
|
||||
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
|
||||
#endif
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
<%
|
||||
require "TemplateCommon"
|
||||
%>
|
||||
|
||||
namespace XLua.CSObjectWrap
|
||||
{
|
||||
public class XLua_Gen_Initer_Register__
|
||||
{
|
||||
<%
|
||||
local split_method_perfix = 'wrapInit'
|
||||
local split_method_count = 0
|
||||
local wrap_in_split_method = 0
|
||||
local max_wrap_in_split_method = 50
|
||||
%>
|
||||
<%ForEachCsList(wraps, function(wrap)%>
|
||||
<%if wrap_in_split_method == 0 then%>static void <%=split_method_perfix%><%=split_method_count%>(LuaEnv luaenv, ObjectTranslator translator)
|
||||
{
|
||||
<%end%>
|
||||
translator.DelayWrapLoader(typeof(<%=CsFullTypeName(wrap)%>), <%=CSVariableName(wrap)%>Wrap.__Register);
|
||||
<%if wrap_in_split_method == max_wrap_in_split_method then
|
||||
wrap_in_split_method = 0
|
||||
split_method_count = split_method_count + 1
|
||||
%>
|
||||
}
|
||||
<%else
|
||||
wrap_in_split_method = wrap_in_split_method + 1
|
||||
end
|
||||
end)%>
|
||||
<% if generic_wraps then
|
||||
for generic_def, instances in pairs(generic_wraps) do
|
||||
for _, args in ipairs(instances) do
|
||||
local generic_arg_list = "<"
|
||||
ForEachCsList(args, function(generic_arg, gai)
|
||||
if gai ~= 0 then generic_arg_list = generic_arg_list .. ", " end
|
||||
generic_arg_list = generic_arg_list .. CsFullTypeName(generic_arg)
|
||||
end)
|
||||
generic_arg_list = generic_arg_list .. ">"
|
||||
|
||||
%>
|
||||
<%if wrap_in_split_method == 0 then%>static void <%=split_method_perfix%><%=split_method_count%>(LuaEnv luaenv, ObjectTranslator translator)
|
||||
{
|
||||
<%end%>
|
||||
translator.DelayWrapLoader(typeof(<%=generic_def.Name:gsub("`%d+", "") .. generic_arg_list%>), <%=CSVariableName(generic_def)%>Wrap<%=generic_arg_list%>.__Register);
|
||||
<%if wrap_in_split_method == max_wrap_in_split_method then
|
||||
wrap_in_split_method = 0
|
||||
split_method_count = split_method_count + 1
|
||||
%>
|
||||
}
|
||||
<%else
|
||||
wrap_in_split_method = wrap_in_split_method + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end%>
|
||||
|
||||
<%if wrap_in_split_method ~= 0 then
|
||||
split_method_count = split_method_count + 1
|
||||
%>}<%end%>
|
||||
|
||||
static void Init(LuaEnv luaenv, ObjectTranslator translator)
|
||||
{
|
||||
<%for i = 1, split_method_count do%>
|
||||
<%=split_method_perfix%><%=(i - 1)%>(luaenv, translator);
|
||||
<%end%>
|
||||
<%ForEachCsList(itf_bridges, function(itf_bridge)%>
|
||||
translator.AddInterfaceBridgeCreator(typeof(<%=CsFullTypeName(itf_bridge)%>), <%=CSVariableName(itf_bridge)%>Bridge.__Create);
|
||||
<%end)%>
|
||||
}
|
||||
|
||||
static XLua_Gen_Initer_Register__()
|
||||
{
|
||||
XLua.LuaEnv.AddIniter(Init);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
namespace XLua
|
||||
{
|
||||
public partial class ObjectTranslator
|
||||
{
|
||||
static XLua.CSObjectWrap.XLua_Gen_Initer_Register__ s_gen_reg_dumb_obj = new XLua.CSObjectWrap.XLua_Gen_Initer_Register__();
|
||||
static XLua.CSObjectWrap.XLua_Gen_Initer_Register__ gen_reg_dumb_obj {get{return s_gen_reg_dumb_obj;}}
|
||||
}
|
||||
|
||||
internal partial class InternalGlobals
|
||||
{
|
||||
<%
|
||||
local type_to_methods = {}
|
||||
local seq_tbl = {}
|
||||
ForEachCsList(extension_methods, function(extension_method, idx)
|
||||
local parameters = extension_method:GetParameters()
|
||||
local type = parameters[0].ParameterType
|
||||
if not type_to_methods[type] then
|
||||
type_to_methods[type] = {type = type}
|
||||
table.insert(seq_tbl, type_to_methods[type])
|
||||
end
|
||||
table.insert(type_to_methods[type], {method = extension_method, index = idx})
|
||||
%>
|
||||
delegate <%=CsFullTypeName(extension_method.ReturnType)%> __GEN_DELEGATE<%=idx%>(<%ForEachCsList(parameters, function(parameter, pi)
|
||||
%><%if pi ~= 0 then%>, <%end%><%if parameter.IsOut then %>out <% elseif parameter.ParameterType.IsByRef then %>ref <% end %> <%=CsFullTypeName(parameter.ParameterType)%> <%=parameter.Name%><%
|
||||
end)%>);
|
||||
<%end)%>
|
||||
static InternalGlobals()
|
||||
{
|
||||
extensionMethodMap = new Dictionary<Type, IEnumerable<MethodInfo>>()
|
||||
{
|
||||
<%for _, methods_info in ipairs(seq_tbl) do%>
|
||||
{typeof(<%=CsFullTypeName(methods_info.type)%>), new List<MethodInfo>(){
|
||||
<% for _, method_info in ipairs(methods_info) do%>
|
||||
new __GEN_DELEGATE<%=method_info.index%>(<%=CsFullTypeName(method_info.method.DeclaringType)%>.<%=method_info.method.Name%>)
|
||||
#if UNITY_WSA && !UNITY_EDITOR
|
||||
.GetMethodInfo(),
|
||||
#else
|
||||
.Method,
|
||||
#endif
|
||||
<% end%>
|
||||
}},
|
||||
<%end%>
|
||||
};
|
||||
|
||||
genTryArrayGetPtr = StaticLuaCallbacks.__tryArrayGet;
|
||||
genTryArraySetPtr = StaticLuaCallbacks.__tryArraySet;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f8b98d26884ed744bb7795397079327
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,140 @@
|
||||
#if USE_UNI_LUA
|
||||
using LuaAPI = UniLua.Lua;
|
||||
using RealStatePtr = UniLua.ILuaState;
|
||||
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
|
||||
#else
|
||||
using LuaAPI = XLua.LuaDLL.Lua;
|
||||
using RealStatePtr = System.IntPtr;
|
||||
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
|
||||
#endif
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
<%
|
||||
require "TemplateCommon"
|
||||
%>
|
||||
|
||||
namespace XLua.CSObjectWrap
|
||||
{
|
||||
public class XLua_Gen_Initer_Register__
|
||||
{
|
||||
<%
|
||||
local split_method_perfix = 'wrapInit'
|
||||
local split_method_count = 0
|
||||
local wrap_in_split_method = 0
|
||||
local max_wrap_in_split_method = 50
|
||||
%>
|
||||
<%ForEachCsList(wraps, function(wrap)%>
|
||||
<%if wrap_in_split_method == 0 then%>static void <%=split_method_perfix%><%=split_method_count%>(LuaEnv luaenv, ObjectTranslator translator)
|
||||
{
|
||||
<%end%>
|
||||
translator.DelayWrapLoader(typeof(<%=CsFullTypeName(wrap)%>), translator.__Register<%=CSVariableName(wrap)%>);
|
||||
<%if wrap_in_split_method == max_wrap_in_split_method then
|
||||
wrap_in_split_method = 0
|
||||
split_method_count = split_method_count + 1
|
||||
%>
|
||||
}
|
||||
<%else
|
||||
wrap_in_split_method = wrap_in_split_method + 1
|
||||
end
|
||||
end)%>
|
||||
<% if generic_wraps then
|
||||
for generic_def, instances in pairs(generic_wraps) do
|
||||
for _, args in ipairs(instances) do
|
||||
local generic_arg_list = "<"
|
||||
ForEachCsList(args, function(generic_arg, gai)
|
||||
if gai ~= 0 then generic_arg_list = generic_arg_list .. ", " end
|
||||
generic_arg_list = generic_arg_list .. CsFullTypeName(generic_arg)
|
||||
end)
|
||||
generic_arg_list = generic_arg_list .. ">"
|
||||
|
||||
%>
|
||||
<%if wrap_in_split_method == 0 then%>static void <%=split_method_perfix%><%=split_method_count%>(LuaEnv luaenv, ObjectTranslator translator)
|
||||
{
|
||||
<%end%>
|
||||
translator.DelayWrapLoader(typeof(<%=generic_def.Name:gsub("`%d+", "") .. generic_arg_list%>), translator.__Register<%=CSVariableName(generic_def)%><%=generic_arg_list%>);
|
||||
<%if wrap_in_split_method == max_wrap_in_split_method then
|
||||
wrap_in_split_method = 0
|
||||
split_method_count = split_method_count + 1
|
||||
%>
|
||||
}
|
||||
<%else
|
||||
wrap_in_split_method = wrap_in_split_method + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end%>
|
||||
|
||||
<%if wrap_in_split_method ~= 0 then
|
||||
split_method_count = split_method_count + 1
|
||||
%>}<%end%>
|
||||
|
||||
static void Init(LuaEnv luaenv, ObjectTranslator translator)
|
||||
{
|
||||
<%for i = 1, split_method_count do%>
|
||||
<%=split_method_perfix%><%=(i - 1)%>(luaenv, translator);
|
||||
<%end%>
|
||||
<%ForEachCsList(itf_bridges, function(itf_bridge)%>
|
||||
translator.AddInterfaceBridgeCreator(typeof(<%=CsFullTypeName(itf_bridge)%>), <%=CSVariableName(itf_bridge)%>Bridge.__Create);
|
||||
<%end)%>
|
||||
}
|
||||
|
||||
static XLua_Gen_Initer_Register__()
|
||||
{
|
||||
XLua.LuaEnv.AddIniter(Init);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
namespace XLua
|
||||
{
|
||||
public partial class ObjectTranslator
|
||||
{
|
||||
static XLua.CSObjectWrap.XLua_Gen_Initer_Register__ s_gen_reg_dumb_obj = new XLua.CSObjectWrap.XLua_Gen_Initer_Register__();
|
||||
static XLua.CSObjectWrap.XLua_Gen_Initer_Register__ gen_reg_dumb_obj {get{return s_gen_reg_dumb_obj;}}
|
||||
}
|
||||
|
||||
internal partial class InternalGlobals
|
||||
{
|
||||
<%
|
||||
local type_to_methods = {}
|
||||
local seq_tbl = {}
|
||||
ForEachCsList(extension_methods, function(extension_method, idx)
|
||||
local parameters = extension_method:GetParameters()
|
||||
local type = parameters[0].ParameterType
|
||||
if not type_to_methods[type] then
|
||||
type_to_methods[type] = {type = type}
|
||||
table.insert(seq_tbl, type_to_methods[type])
|
||||
end
|
||||
table.insert(type_to_methods[type], {method = extension_method, index = idx})
|
||||
%>
|
||||
delegate <%=CsFullTypeName(extension_method.ReturnType)%> __GEN_DELEGATE<%=idx%>(<%ForEachCsList(parameters, function(parameter, pi)
|
||||
%><%if pi ~= 0 then%>, <%end%><%if parameter.IsOut then %>out <% elseif parameter.ParameterType.IsByRef then %>ref <% end %> <%=CsFullTypeName(parameter.ParameterType)%> <%=parameter.Name%><%
|
||||
end)%>);
|
||||
<%end)%>
|
||||
static InternalGlobals()
|
||||
{
|
||||
extensionMethodMap = new Dictionary<Type, IEnumerable<MethodInfo>>()
|
||||
{
|
||||
<%for _, methods_info in ipairs(seq_tbl) do%>
|
||||
{typeof(<%=CsFullTypeName(methods_info.type)%>), new List<MethodInfo>(){
|
||||
<% for _, method_info in ipairs(methods_info) do%>
|
||||
new __GEN_DELEGATE<%=method_info.index%>(<%=CsFullTypeName(method_info.method.DeclaringType)%>.<%=method_info.method.Name%>)
|
||||
#if UNITY_WSA && !UNITY_EDITOR
|
||||
.GetMethodInfo(),
|
||||
#else
|
||||
.Method,
|
||||
#endif
|
||||
<% end%>
|
||||
}},
|
||||
<%end%>
|
||||
};
|
||||
|
||||
genTryArrayGetPtr = StaticLuaCallbacks.__tryArrayGet;
|
||||
genTryArraySetPtr = StaticLuaCallbacks.__tryArraySet;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 576f223a4bde7f94a98af12c317365ee
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,233 @@
|
||||
#if USE_UNI_LUA
|
||||
using LuaAPI = UniLua.Lua;
|
||||
using RealStatePtr = UniLua.ILuaState;
|
||||
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
|
||||
#else
|
||||
using LuaAPI = XLua.LuaDLL.Lua;
|
||||
using RealStatePtr = System.IntPtr;
|
||||
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
|
||||
#endif
|
||||
|
||||
using System;
|
||||
<%
|
||||
require "TemplateCommon"
|
||||
%>
|
||||
|
||||
namespace XLua
|
||||
{
|
||||
public partial class ObjectTranslator
|
||||
{
|
||||
<%if purevaluetypes.Count > 0 then
|
||||
local init_class_name = "IniterAdder" .. CSVariableName(purevaluetypes[0].Type)
|
||||
%>
|
||||
class <%=init_class_name%>
|
||||
{
|
||||
static <%=init_class_name%>()
|
||||
{
|
||||
LuaEnv.AddIniter(Init);
|
||||
}
|
||||
|
||||
static void Init(LuaEnv luaenv, ObjectTranslator translator)
|
||||
{
|
||||
<%ForEachCsList(purevaluetypes, function(type_info)
|
||||
if not type_info.Type.IsValueType then return end
|
||||
local full_type_name = CsFullTypeName(type_info.Type)%>
|
||||
translator.RegisterPushAndGetAndUpdate<<%=full_type_name%>>(translator.Push<%=CSVariableName(type_info.Type)%>, translator.Get, translator.Update<%=CSVariableName(type_info.Type)%>);<%
|
||||
end)%>
|
||||
<%ForEachCsList(tableoptimzetypes, function(type_info)
|
||||
local full_type_name = CsFullTypeName(type_info.Type)%>
|
||||
translator.RegisterCaster<<%=full_type_name%>>(translator.Get);<%
|
||||
end)%>
|
||||
}
|
||||
}
|
||||
|
||||
static <%=init_class_name%> s_<%=init_class_name%>_dumb_obj = new <%=init_class_name%>();
|
||||
static <%=init_class_name%> <%=init_class_name%>_dumb_obj {get{return s_<%=init_class_name%>_dumb_obj;}}
|
||||
<%end%>
|
||||
|
||||
<%ForEachCsList(purevaluetypes, function(type_info)
|
||||
local type_id_var_name = CSVariableName(type_info.Type) .. '_TypeID'
|
||||
local enum_ref_var_name = CSVariableName(type_info.Type)..'_EnumRef'
|
||||
local full_type_name = CsFullTypeName(type_info.Type)
|
||||
local is_enum = type_info.Type.IsEnum
|
||||
%>int <%=type_id_var_name%> = -1;<%if is_enum then%>
|
||||
int <%=enum_ref_var_name%> = -1;
|
||||
<%end%>
|
||||
public void Push<%=CSVariableName(type_info.Type)%>(RealStatePtr L, <%=full_type_name%> val)
|
||||
{
|
||||
if (<%=type_id_var_name%> == -1)
|
||||
{
|
||||
bool is_first;
|
||||
<%=type_id_var_name%> = getTypeId(L, typeof(<%=full_type_name%>), out is_first);
|
||||
<%if is_enum then%>
|
||||
if (<%=enum_ref_var_name%> == -1)
|
||||
{
|
||||
Utils.LoadCSTable(L, typeof(<%=full_type_name%>));
|
||||
<%=enum_ref_var_name%> = LuaAPI.luaL_ref(L, LuaIndexes.LUA_REGISTRYINDEX);
|
||||
}
|
||||
<%end%>
|
||||
}
|
||||
<%if is_enum then%>
|
||||
if (LuaAPI.xlua_tryget_cachedud(L, (int)val, <%=enum_ref_var_name%>) == 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
<%
|
||||
end
|
||||
if type_info.Flag == CS.XLua.OptimizeFlag.PackAsTable then
|
||||
%>
|
||||
<%if PushObjectNeedTranslator(type_info) then %> ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);<%end%>
|
||||
LuaAPI.xlua_pushcstable(L, <%=type_info.FieldInfos.Count%>, <%=type_id_var_name%>);
|
||||
<%ForEachCsList(type_info.FieldInfos, function(fieldInfo)%>
|
||||
LuaAPI.xlua_pushasciistring(L, "<%=fieldInfo.Name%>");
|
||||
<%=GetPushStatement(fieldInfo.Type, "val."..fieldInfo.Name)%>;
|
||||
LuaAPI.lua_rawset(L, -3);
|
||||
<%end)%>
|
||||
<%else%>
|
||||
IntPtr buff = LuaAPI.xlua_pushstruct(L, <%=is_enum and 4 or type_info.Size%>, <%=type_id_var_name%>);
|
||||
if (!CopyByValue.Pack(buff, 0, <%=is_enum and "(int)" or ""%>val))
|
||||
{
|
||||
throw new Exception("pack fail fail for <%=full_type_name%> ,value="+val);
|
||||
}
|
||||
<%
|
||||
end
|
||||
if is_enum then
|
||||
%>
|
||||
LuaAPI.lua_getref(L, <%=enum_ref_var_name%>);
|
||||
LuaAPI.lua_pushvalue(L, -2);
|
||||
LuaAPI.xlua_rawseti(L, -2, (int)val);
|
||||
LuaAPI.lua_pop(L, 1);
|
||||
<%end%>
|
||||
}
|
||||
|
||||
public void Get(RealStatePtr L, int index, out <%=full_type_name%> val)
|
||||
{
|
||||
LuaTypes type = LuaAPI.lua_type(L, index);
|
||||
if (type == LuaTypes.LUA_TUSERDATA )
|
||||
{
|
||||
if (LuaAPI.xlua_gettypeid(L, index) != <%=type_id_var_name%>)
|
||||
{
|
||||
throw new Exception("invalid userdata for <%=full_type_name%>");
|
||||
}
|
||||
|
||||
IntPtr buff = LuaAPI.lua_touserdata(L, index);<%if is_enum then%>
|
||||
int e;
|
||||
<%end%>if (!CopyByValue.UnPack(buff, 0, out <%=is_enum and "e" or "val"%>))
|
||||
{
|
||||
throw new Exception("unpack fail for <%=full_type_name%>");
|
||||
}<%if is_enum then%>
|
||||
val = (<%=full_type_name%>)e;
|
||||
<%end%>
|
||||
}<%if not is_enum then%>
|
||||
else if (type ==LuaTypes.LUA_TTABLE)
|
||||
{
|
||||
CopyByValue.UnPack(this, L, index, out val);
|
||||
}<%end%>
|
||||
else
|
||||
{
|
||||
val = (<%=full_type_name%>)objectCasters.GetCaster(typeof(<%=full_type_name%>))(L, index, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void Update<%=CSVariableName(type_info.Type)%>(RealStatePtr L, int index, <%=full_type_name%> val)
|
||||
{
|
||||
<%if type_info.Flag == CS.XLua.OptimizeFlag.PackAsTable then%>
|
||||
if (LuaAPI.lua_type(L, index) == LuaTypes.LUA_TTABLE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
<%else%>
|
||||
if (LuaAPI.lua_type(L, index) == LuaTypes.LUA_TUSERDATA)
|
||||
{
|
||||
if (LuaAPI.xlua_gettypeid(L, index) != <%=type_id_var_name%>)
|
||||
{
|
||||
throw new Exception("invalid userdata for <%=full_type_name%>");
|
||||
}
|
||||
|
||||
IntPtr buff = LuaAPI.lua_touserdata(L, index);
|
||||
if (!CopyByValue.Pack(buff, 0, <%=is_enum and "(int)" or ""%>val))
|
||||
{
|
||||
throw new Exception("pack fail for <%=full_type_name%> ,value="+val);
|
||||
}
|
||||
}
|
||||
<%end%>
|
||||
else
|
||||
{
|
||||
throw new Exception("try to update a data with lua type:" + LuaAPI.lua_type(L, index));
|
||||
}
|
||||
}
|
||||
|
||||
<%end)%>
|
||||
// table cast optimze
|
||||
<%ForEachCsList(tableoptimzetypes, function(type_info)
|
||||
local full_type_name = CsFullTypeName(type_info.Type)
|
||||
%>
|
||||
public void Get(RealStatePtr L, int index, out <%=full_type_name%> val)
|
||||
{
|
||||
LuaTypes type = LuaAPI.lua_type(L, index);
|
||||
if (type == LuaTypes.LUA_TUSERDATA )
|
||||
{
|
||||
val = (<%=full_type_name%>)FastGetCSObj(L, index);
|
||||
}
|
||||
else if (type == LuaTypes.LUA_TTABLE)
|
||||
{
|
||||
val = new <%=full_type_name%>();
|
||||
int top = LuaAPI.lua_gettop(L);
|
||||
<%ForEachCsList(type_info.Fields, function(fieldInfo)%>
|
||||
if (Utils.LoadField(L, index, "<%=fieldInfo.Name%>"))
|
||||
{
|
||||
Get(L, top + 1, out val.<%=fieldInfo.Name%>);
|
||||
}
|
||||
LuaAPI.lua_pop(L, 1);
|
||||
<%end)%>
|
||||
}<%if not type_info.Type.IsValueType then%>
|
||||
else if (type == LuaTypes.LUA_TNIL || type == LuaTypes.LUA_TNONE)
|
||||
{
|
||||
val = null;
|
||||
}<%end%>
|
||||
else
|
||||
{
|
||||
throw new Exception("can not cast " + LuaAPI.lua_type(L, index) + " to " + typeof(<%=full_type_name%>));
|
||||
}
|
||||
}
|
||||
<%end)%>
|
||||
|
||||
}
|
||||
|
||||
public partial class StaticLuaCallbacks
|
||||
{
|
||||
internal static bool __tryArrayGet(Type type, RealStatePtr L, ObjectTranslator translator, object obj, int index)
|
||||
{
|
||||
<%ForEachCsList(purevaluetypes, function(type_info, idx)
|
||||
if not type_info.Type.IsValueType then return end
|
||||
local full_type_name = CsFullTypeName(type_info.Type)
|
||||
%>
|
||||
<%=(idx == 0 and '' or 'else ')%>if (type == typeof(<%=full_type_name%>[]))
|
||||
{
|
||||
<%=full_type_name%>[] array = obj as <%=full_type_name%>[];
|
||||
translator.Push<%=CSVariableName(type_info.Type)%>(L, array[index]);
|
||||
return true;
|
||||
}<%
|
||||
end)%>
|
||||
return false;
|
||||
}
|
||||
|
||||
internal static bool __tryArraySet(Type type, RealStatePtr L, ObjectTranslator translator, object obj, int array_idx, int obj_idx)
|
||||
{
|
||||
<%
|
||||
local is_first = true
|
||||
ForEachCsList(purevaluetypes, tableoptimzetypes, function(type_info)
|
||||
local full_type_name = CsFullTypeName(type_info.Type)
|
||||
%>
|
||||
<%=(is_first and '' or 'else ')%>if (type == typeof(<%=full_type_name%>[]))
|
||||
{
|
||||
<%=full_type_name%>[] array = obj as <%=full_type_name%>[];
|
||||
translator.Get(L, obj_idx, out array[array_idx]);
|
||||
return true;
|
||||
}<%
|
||||
is_first = false
|
||||
end)%>
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 17e78feb6da0911498d02df8dc493dae
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,123 @@
|
||||
#if USE_UNI_LUA
|
||||
using LuaAPI = UniLua.Lua;
|
||||
using RealStatePtr = UniLua.ILuaState;
|
||||
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
|
||||
#else
|
||||
using LuaAPI = XLua.LuaDLL.Lua;
|
||||
using RealStatePtr = System.IntPtr;
|
||||
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
|
||||
#endif
|
||||
|
||||
using System;
|
||||
<%
|
||||
require "TemplateCommon"
|
||||
%>
|
||||
|
||||
namespace XLua
|
||||
{
|
||||
public static partial class CopyByValue
|
||||
{
|
||||
<%ForEachCsList(type_infos, function(type_info)
|
||||
local full_type_name = CsFullTypeName(type_info.Type)
|
||||
%>
|
||||
<%if type_info.IsRoot then
|
||||
ForEachCsList(type_info.FieldInfos, function(fieldInfo) fieldInfo.Name = UnK(fieldInfo.Name) end)
|
||||
%>
|
||||
public static void UnPack(ObjectTranslator translator, RealStatePtr L, int idx, out <%=full_type_name%> val)
|
||||
{
|
||||
val = new <%=full_type_name%>();
|
||||
int top = LuaAPI.lua_gettop(L);
|
||||
<%ForEachCsList(type_info.FieldInfos, function(fieldInfo)%>
|
||||
if (Utils.LoadField(L, idx, "<%=fieldInfo.Name%>"))
|
||||
{
|
||||
<%if fieldInfo.IsField then%>
|
||||
translator.Get(L, top + 1, out val.<%=fieldInfo.Name%>);
|
||||
<%else%>
|
||||
var <%=fieldInfo.Name%> = val.<%=fieldInfo.Name%>;
|
||||
translator.Get(L, top + 1, out <%=fieldInfo.Name%>);
|
||||
val.<%=fieldInfo.Name%> = <%=fieldInfo.Name%>;
|
||||
<%end%>
|
||||
}
|
||||
LuaAPI.lua_pop(L, 1);
|
||||
<%end)%>
|
||||
}
|
||||
<%end%>
|
||||
public static bool Pack(IntPtr buff, int offset, <%=full_type_name%> field)
|
||||
{
|
||||
<%
|
||||
local offset_inner = 0
|
||||
if not type_info.FieldGroup then
|
||||
ForEachCsList(type_info.FieldInfos, function(fieldInfo)
|
||||
%>
|
||||
if(!Pack(buff, offset<%=(offset_inner == 0 and "" or (" + " .. offset_inner))%>, field.<%=fieldInfo.Name%>))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
<%
|
||||
offset_inner = offset_inner + fieldInfo.Size
|
||||
end)
|
||||
else
|
||||
ForEachCsList(type_info.FieldGroup, function(group)
|
||||
%>
|
||||
if(!LuaAPI.xlua_pack_float<%=(group.Count == 1 and "" or group.Count)%>(buff, offset<%=(offset_inner == 0 and "" or (" + " .. offset_inner))%><%
|
||||
ForEachCsList(group, function(fieldInfo, i)
|
||||
%>, field.<%=fieldInfo.Name%><%
|
||||
end)
|
||||
%>))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
<%
|
||||
offset_inner = offset_inner + group.Count * 4
|
||||
end)
|
||||
end%>
|
||||
return true;
|
||||
}
|
||||
public static bool UnPack(IntPtr buff, int offset, out <%=full_type_name%> field)
|
||||
{
|
||||
field = default(<%=full_type_name%>);
|
||||
<%
|
||||
local offset_inner = 0
|
||||
if not type_info.FieldGroup then
|
||||
ForEachCsList(type_info.FieldInfos, function(fieldInfo)
|
||||
if fieldInfo.IsField then
|
||||
%>
|
||||
if(!UnPack(buff, offset<%=(offset_inner == 0 and "" or (" + " .. offset_inner))%>, out field.<%=fieldInfo.Name%>))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
<%else%>
|
||||
var <%=fieldInfo.Name%> = field.<%=fieldInfo.Name%>;
|
||||
if(!UnPack(buff, offset<%=(offset_inner == 0 and "" or (" + " .. offset_inner))%>, out <%=fieldInfo.Name%>))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
field.<%=fieldInfo.Name%> = <%=fieldInfo.Name%>;
|
||||
<%
|
||||
end
|
||||
offset_inner = offset_inner + fieldInfo.Size
|
||||
end)
|
||||
else
|
||||
ForEachCsList(type_info.FieldGroup, function(group)
|
||||
%>
|
||||
<%ForEachCsList(group, function(fieldInfo)%>float <%=fieldInfo.Name%> = default(float);
|
||||
<%end)%>
|
||||
if(!LuaAPI.xlua_unpack_float<%=(group.Count == 1 and "" or group.Count)%>(buff, offset<%=(offset_inner == 0 and "" or (" + " .. offset_inner))%><%
|
||||
ForEachCsList(group, function(fieldInfo)
|
||||
%>, out <%=fieldInfo.Name%><%
|
||||
end)
|
||||
%>))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
<%ForEachCsList(group, function(fieldInfo)%>field.<%=fieldInfo.Name%> = <%=fieldInfo.Name%>;
|
||||
<%end)%>
|
||||
<%
|
||||
offset_inner = offset_inner + group.Count * 4
|
||||
end)
|
||||
end%>
|
||||
return true;
|
||||
}
|
||||
<%end)%>
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 434afb93855cf6544a243bdeccb0c7e4
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,472 @@
|
||||
-- Tencent is pleased to support the open source community by making xLua available.
|
||||
-- Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
-- Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
-- http://opensource.org/licenses/MIT
|
||||
-- Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
|
||||
local friendlyNameMap = {
|
||||
["System.Object"] = "object",
|
||||
["System.String"] = "string",
|
||||
["System.Boolean"] = "bool",
|
||||
["System.Byte"] = "byte",
|
||||
["System.Char"] = "char",
|
||||
["System.Decimal"] = "decimal",
|
||||
["System.Double"] = "double",
|
||||
["System.Int16"] = "short",
|
||||
["System.Int32"] = "int",
|
||||
["System.Int64"] = "long",
|
||||
["System.SByte"] = "sbyte",
|
||||
["System.Single"] = "float",
|
||||
["System.UInt16"] = "ushort",
|
||||
["System.UInt32"] = "uint",
|
||||
["System.UInt64"] = "ulong",
|
||||
["System.Void"] = "void",
|
||||
}
|
||||
|
||||
local csKeywords = {
|
||||
"abstract", "as", "base", "bool",
|
||||
"break", "byte", "case", "catch",
|
||||
"char", "checked", "class", "const",
|
||||
"continue", "decimal", "default", "delegate",
|
||||
"do", "double", "else", "enum",
|
||||
"event", "explicit", "extern", "false",
|
||||
"finally", "fixed", "float", "for",
|
||||
"foreach", "goto", "if", "implicit",
|
||||
"in", "int", "interface",
|
||||
"internal", "is", "lock", "long",
|
||||
"namespace", "new", "null", "object",
|
||||
"operator", "out", "override",
|
||||
"params", "private", "protected", "public",
|
||||
"readonly", "ref", "return", "sbyte",
|
||||
"sealed", "short", "sizeof", "stackalloc",
|
||||
"static", "string", "struct", "switch",
|
||||
"this", "throw", "true", "try",
|
||||
"typeof", "uint", "ulong", "unchecked",
|
||||
"unsafe", "ushort", "using", "virtual",
|
||||
"void", "volatile", "while"
|
||||
}
|
||||
|
||||
for _, kw in ipairs(csKeywords) do
|
||||
csKeywords[kw] = '@'..kw
|
||||
end
|
||||
for i = 1, #csKeywords do
|
||||
csKeywords[i] = nil
|
||||
end
|
||||
|
||||
function UnK(symbol)
|
||||
return csKeywords[symbol] or symbol
|
||||
end
|
||||
|
||||
local fixChecker = {
|
||||
--["System.String"] = "LuaAPI.lua_isstring",
|
||||
["System.Boolean"] = "LuaTypes.LUA_TBOOLEAN == LuaAPI.lua_type",
|
||||
["System.Byte"] = "LuaTypes.LUA_TNUMBER == LuaAPI.lua_type",
|
||||
["System.Char"] = "LuaTypes.LUA_TNUMBER == LuaAPI.lua_type",
|
||||
--["System.Decimal"] = "LuaTypes.LUA_TNUMBER == LuaAPI.lua_type",
|
||||
["System.Double"] = "LuaTypes.LUA_TNUMBER == LuaAPI.lua_type",
|
||||
["System.Int16"] = "LuaTypes.LUA_TNUMBER == LuaAPI.lua_type",
|
||||
["System.Int32"] = "LuaTypes.LUA_TNUMBER == LuaAPI.lua_type",
|
||||
--["System.Int64"] = "LuaTypes.LUA_TNUMBER == LuaAPI.lua_type",
|
||||
["System.SByte"] = "LuaTypes.LUA_TNUMBER == LuaAPI.lua_type",
|
||||
["System.Single"] = "LuaTypes.LUA_TNUMBER == LuaAPI.lua_type",
|
||||
["System.UInt16"] = "LuaTypes.LUA_TNUMBER == LuaAPI.lua_type",
|
||||
["System.UInt32"] = "LuaTypes.LUA_TNUMBER == LuaAPI.lua_type",
|
||||
--["System.UInt64"] = "LuaTypes.LUA_TNUMBER == LuaAPI.lua_type",
|
||||
["System.IntPtr"] = "LuaTypes.LUA_TLIGHTUSERDATA == LuaAPI.lua_type",
|
||||
}
|
||||
|
||||
local typedCaster = {
|
||||
["System.Byte"] = "LuaAPI.xlua_tointeger",
|
||||
["System.Char"] = "LuaAPI.xlua_tointeger",
|
||||
["System.Int16"] = "LuaAPI.xlua_tointeger",
|
||||
["System.SByte"] = "LuaAPI.xlua_tointeger",
|
||||
["System.Single"] = "LuaAPI.lua_tonumber",
|
||||
["System.UInt16"] = "LuaAPI.xlua_tointeger",
|
||||
}
|
||||
|
||||
local fixCaster = {
|
||||
["System.Double"] = "LuaAPI.lua_tonumber",
|
||||
["System.String"] = "LuaAPI.lua_tostring",
|
||||
["System.Boolean"] = "LuaAPI.lua_toboolean",
|
||||
["System.Byte[]"] = "LuaAPI.lua_tobytes",
|
||||
["System.IntPtr"] = "LuaAPI.lua_touserdata",
|
||||
["System.UInt32"] = "LuaAPI.xlua_touint",
|
||||
["System.UInt64"] = "LuaAPI.lua_touint64",
|
||||
["System.Int32"] = "LuaAPI.xlua_tointeger",
|
||||
["System.Int64"] = "LuaAPI.lua_toint64",
|
||||
}
|
||||
|
||||
local fixPush = {
|
||||
["System.Byte"] = "LuaAPI.xlua_pushinteger",
|
||||
["System.Char"] = "LuaAPI.xlua_pushinteger",
|
||||
["System.Int16"] = "LuaAPI.xlua_pushinteger",
|
||||
["System.Int32"] = "LuaAPI.xlua_pushinteger",
|
||||
["System.Int64"] = "LuaAPI.lua_pushint64",
|
||||
["System.SByte"] = "LuaAPI.xlua_pushinteger",
|
||||
["System.Single"] = "LuaAPI.lua_pushnumber",
|
||||
["System.UInt16"] = "LuaAPI.xlua_pushinteger",
|
||||
["System.UInt32"] = "LuaAPI.xlua_pushuint",
|
||||
["System.UInt64"] = "LuaAPI.lua_pushuint64",
|
||||
["System.Single"] = "LuaAPI.lua_pushnumber",
|
||||
["System.Double"] = "LuaAPI.lua_pushnumber",
|
||||
["System.String"] = "LuaAPI.lua_pushstring",
|
||||
["System.Byte[]"] = "LuaAPI.lua_pushstring",
|
||||
["System.Boolean"] = "LuaAPI.lua_pushboolean",
|
||||
["System.IntPtr"] = "LuaAPI.lua_pushlightuserdata",
|
||||
["System.Decimal"] = "translator.PushDecimal",
|
||||
["System.Object"] = "translator.PushAny",
|
||||
}
|
||||
|
||||
local notranslator = {
|
||||
["System.Byte"] = true,
|
||||
["System.Char"] = true,
|
||||
["System.Int16"] = true,
|
||||
["System.Int32"] = true,
|
||||
["System.Int64"] = true,
|
||||
["System.SByte"] = true,
|
||||
["System.Single"] = true,
|
||||
["System.UInt16"] = true,
|
||||
["System.UInt32"] = true,
|
||||
["System.UInt64"] = true,
|
||||
["System.Double"] = true,
|
||||
["System.String"] = true,
|
||||
["System.Boolean"] = true,
|
||||
["System.Void"] = true,
|
||||
["System.IntPtr"] = true,
|
||||
["System.Byte[]"] = true,
|
||||
}
|
||||
|
||||
function ForEachCsList(...)
|
||||
local list_count = select('#', ...) - 1
|
||||
local callback = select(list_count + 1, ...)
|
||||
for i = 1, list_count do
|
||||
local list = select(i, ...)
|
||||
for i = 0, (list.Count or list.Length) - 1 do
|
||||
callback(list[i], i)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function CalcCsList(list, predicate)
|
||||
local count = 0
|
||||
for i = 0, (list.Count or list.Length) - 1 do
|
||||
if predicate(list[i], i) then count = count + 1 end
|
||||
end
|
||||
return count
|
||||
end
|
||||
|
||||
function IfAny(list, predicate)
|
||||
for i = 0, (list.Count or list.Length) - 1 do
|
||||
if predicate(list[i], i) then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local genPushAndUpdateTypes
|
||||
|
||||
function SetGenPushAndUpdateTypes(list)
|
||||
genPushAndUpdateTypes = {}
|
||||
ForEachCsList(list, function(t)
|
||||
genPushAndUpdateTypes[t] = true
|
||||
end)
|
||||
end
|
||||
|
||||
local xLuaClasses
|
||||
function SetXLuaClasses(list)
|
||||
xLuaClasses = {}
|
||||
ForEachCsList(list, function(t)
|
||||
xLuaClasses[t.Name] = true
|
||||
end)
|
||||
end
|
||||
|
||||
local objType = typeof(CS.System.Object)
|
||||
local valueType = typeof(CS.System.ValueType)
|
||||
|
||||
local function _CsFullTypeName(t)
|
||||
if t.IsArray then
|
||||
local element_name, element_is_array = _CsFullTypeName(t:GetElementType())
|
||||
if element_is_array then
|
||||
local bracket_pos = element_name:find('%[')
|
||||
return element_name:sub(1, bracket_pos - 1) .. '[' .. string.rep(',', t:GetArrayRank() - 1) .. ']' .. element_name:sub(bracket_pos, -1), true
|
||||
else
|
||||
return element_name .. '[' .. string.rep(',', t:GetArrayRank() - 1) .. ']', true
|
||||
end
|
||||
elseif t.IsByRef then
|
||||
return _CsFullTypeName(t:GetElementType())
|
||||
elseif t.IsGenericParameter then
|
||||
return (t.BaseType == objType or t.BaseType == valueType) and t.Name or _CsFullTypeName(t.BaseType) --TODO:应该判断是否类型约束
|
||||
end
|
||||
|
||||
local name = t.FullName:gsub("&", ""):gsub("%+", ".")
|
||||
if not t.IsGenericType then
|
||||
return friendlyNameMap[name] or name
|
||||
end
|
||||
local genericParameter = ""
|
||||
ForEachCsList(t:GetGenericArguments(), function(at, ati)
|
||||
if ati ~= 0 then genericParameter = genericParameter .. ', ' end
|
||||
genericParameter = genericParameter .. _CsFullTypeName(at)
|
||||
end)
|
||||
return name:gsub("`%d+", '<' .. genericParameter .. '>'):gsub("%[[^,%]].*", ""), false
|
||||
end
|
||||
|
||||
function CsFullTypeName(t)
|
||||
if t.DeclaringType then
|
||||
local name = _CsFullTypeName(t)
|
||||
local declaringTypeName = _CsFullTypeName(t.DeclaringType);
|
||||
return xLuaClasses[declaringTypeName] and ("global::" .. name) or name
|
||||
else
|
||||
local name = _CsFullTypeName(t)
|
||||
return xLuaClasses[name] and ("global::" .. name) or name
|
||||
end
|
||||
end
|
||||
|
||||
function CSVariableName(t)
|
||||
if t.IsArray then
|
||||
return CSVariableName(t:GetElementType()) .. '_'.. t:GetArrayRank() ..'_'
|
||||
end
|
||||
return t:ToString():gsub("&", ""):gsub("%+", ""):gsub("`", "_"):gsub("%.", ""):gsub("%[", "_"):gsub("%]", "_"):gsub(",", "")
|
||||
end
|
||||
|
||||
local function getSafeFullName(t)
|
||||
if t == nil then
|
||||
return ""
|
||||
end
|
||||
|
||||
if t.IsGenericParameter then
|
||||
return t.BaseType == objType and t.Name or getSafeFullName(t.BaseType)
|
||||
end
|
||||
|
||||
if not t.FullName then return "" end
|
||||
|
||||
return t.FullName:gsub("&", "")
|
||||
end
|
||||
|
||||
function GetCheckStatement(t, idx, is_v_params)
|
||||
local cond_start = is_v_params and "(LuaTypes.LUA_TNONE == LuaAPI.lua_type(L, ".. idx ..") || " or ""
|
||||
local cond_end = is_v_params and ")" or ""
|
||||
local testname = getSafeFullName(t)
|
||||
if testname == "System.String" or testname == "System.Byte[]" then
|
||||
return cond_start .. "(LuaAPI.lua_isnil(L, " .. idx .. ") || LuaAPI.lua_type(L, ".. idx ..") == LuaTypes.LUA_TSTRING)" .. cond_end
|
||||
elseif testname == "System.Int64" then
|
||||
return cond_start .. "(LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, ".. idx ..") || LuaAPI.lua_isint64(L, ".. idx .."))" .. cond_end
|
||||
elseif testname == "System.UInt64" then
|
||||
return cond_start .. "(LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, ".. idx ..") || LuaAPI.lua_isuint64(L, ".. idx .."))" .. cond_end
|
||||
elseif testname == "System.Decimal" then
|
||||
return cond_start .. "(LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, ".. idx ..") || translator.IsDecimal(L, ".. idx .."))" .. cond_end
|
||||
elseif testname == "XLua.LuaTable" then
|
||||
return cond_start .. "(LuaAPI.lua_isnil(L, " .. idx .. ") || LuaAPI.lua_type(L, ".. idx ..") == LuaTypes.LUA_TTABLE)" .. cond_end
|
||||
elseif testname == "XLua.LuaFunction" then
|
||||
return cond_start .. "(LuaAPI.lua_isnil(L, " .. idx .. ") || LuaAPI.lua_type(L, ".. idx ..") == LuaTypes.LUA_TFUNCTION)" .. cond_end
|
||||
end
|
||||
return cond_start .. (fixChecker[testname] or ("translator.Assignable<" .. CsFullTypeName(t).. ">")) .. "(L, ".. idx ..")" .. cond_end
|
||||
end
|
||||
|
||||
local delegateType = typeof(CS.System.Delegate)
|
||||
local ExtensionAttribute = typeof(CS.System.Runtime.CompilerServices.ExtensionAttribute)
|
||||
|
||||
function IsExtensionMethod(method)
|
||||
return method:IsDefined(ExtensionAttribute, false)
|
||||
end
|
||||
|
||||
function IsDelegate(t)
|
||||
return delegateType:IsAssignableFrom(t)
|
||||
end
|
||||
|
||||
function MethodParameters(method)
|
||||
if not IsExtensionMethod(method) then
|
||||
return method:GetParameters()
|
||||
else
|
||||
local parameters = method:GetParameters()
|
||||
if parameters[0].ParameterType.IsInterface then
|
||||
return parameters
|
||||
end
|
||||
local ret = {}
|
||||
for i = 1, parameters.Length - 1 do
|
||||
ret[i - 1] = parameters[i]
|
||||
end
|
||||
ret.Length = parameters.Length - 1
|
||||
return ret
|
||||
end
|
||||
end
|
||||
|
||||
function IsStruct(t)
|
||||
if t.IsByRef then t = t:GetElementType() end
|
||||
return t.IsValueType and not t.IsPrimitive
|
||||
end
|
||||
|
||||
function NeedUpdate(t)
|
||||
if t.IsByRef then t = t:GetElementType() end
|
||||
return t.IsValueType and not t.IsPrimitive and not t.IsEnum and t ~= typeof(CS.System.Decimal)
|
||||
end
|
||||
|
||||
function GetCasterStatement(t, idx, var_name, need_declare, is_v_params)
|
||||
local testname = getSafeFullName(t)
|
||||
local statement = ""
|
||||
local is_struct = IsStruct(t)
|
||||
|
||||
if need_declare then
|
||||
statement = CsFullTypeName(t) .. " " .. var_name
|
||||
if is_struct and not typedCaster[testname] and not fixCaster[testname] then
|
||||
statement = statement .. ";"
|
||||
else
|
||||
statement = statement .. " = "
|
||||
end
|
||||
elseif not is_struct then
|
||||
statement = var_name .. " = "
|
||||
end
|
||||
|
||||
if is_v_params then
|
||||
return statement .. "translator.GetParams<" .. CsFullTypeName(t:GetElementType()).. ">" .. "(L, ".. idx ..")"
|
||||
elseif typedCaster[testname] then
|
||||
return statement .. "(" .. CsFullTypeName(t) .. ")" ..typedCaster[testname] .. "(L, ".. idx ..")"
|
||||
elseif IsDelegate(t) then
|
||||
return statement .. "translator.GetDelegate<" .. CsFullTypeName(t).. ">" .. "(L, ".. idx ..")"
|
||||
elseif fixCaster[testname] then
|
||||
return statement .. fixCaster[testname] .. "(L, ".. idx ..")"
|
||||
elseif testname == "System.Object" then
|
||||
return statement .. "translator.GetObject(L, ".. idx ..", typeof(" .. CsFullTypeName(t) .."))"
|
||||
elseif is_struct then
|
||||
return statement .. "translator.Get(L, ".. idx ..", out " .. var_name .. ")"
|
||||
elseif t.IsGenericParameter and not t.DeclaringMethod then
|
||||
return statement .. "translator.GetByType<"..t.Name..">(L, ".. idx ..")"
|
||||
else
|
||||
return statement .. "("..CsFullTypeName(t)..")translator.GetObject(L, ".. idx ..", typeof(" .. CsFullTypeName(t) .."))"
|
||||
end
|
||||
end
|
||||
|
||||
local paramsAttriType = typeof(CS.System.ParamArrayAttribute)
|
||||
function IsParams(pi)
|
||||
if (not pi.IsDefined) then
|
||||
return pi.IsParamArray
|
||||
end
|
||||
return pi:IsDefined(paramsAttriType, false)
|
||||
end
|
||||
|
||||
local obsoluteAttriType = typeof(CS.System.ObsoleteAttribute)
|
||||
function IsObsolute(f)
|
||||
return f:IsDefined(obsoluteAttriType, false)
|
||||
end
|
||||
|
||||
local objectType = typeof(CS.System.Object)
|
||||
function GetSelfStatement(t)
|
||||
local fulltypename = CsFullTypeName(t)
|
||||
local is_struct = IsStruct(t)
|
||||
if is_struct then
|
||||
return fulltypename .. " gen_to_be_invoked;translator.Get(L, 1, out gen_to_be_invoked)"
|
||||
else
|
||||
if t == objectType then
|
||||
return "object gen_to_be_invoked = translator.FastGetCSObj(L, 1)"
|
||||
else
|
||||
return fulltypename .. " gen_to_be_invoked = (" .. fulltypename .. ")translator.FastGetCSObj(L, 1)"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local GetNullableUnderlyingType = CS.System.Nullable.GetUnderlyingType
|
||||
|
||||
function GetPushStatement(t, variable, is_v_params)
|
||||
if is_v_params then
|
||||
local item_push = GetPushStatement(t:GetElementType(), variable..'[__gen_i]')
|
||||
return 'if ('.. variable ..' != null) { for (int __gen_i = 0; __gen_i < ' .. variable .. '.Length; ++__gen_i) ' .. item_push .. '; }'
|
||||
end
|
||||
if t.IsByRef then t = t:GetElementType() end
|
||||
local testname = getSafeFullName(t)
|
||||
if fixPush[testname] then
|
||||
return fixPush[testname] .. "(L, ".. variable ..")"
|
||||
elseif genPushAndUpdateTypes[t] then
|
||||
return "translator.Push".. CSVariableName(t) .."(L, "..variable..")"
|
||||
elseif t.IsGenericParameter and not t.DeclaringMethod then
|
||||
return "translator.PushByType(L, "..variable..")"
|
||||
elseif t.IsInterface or GetNullableUnderlyingType(t) then
|
||||
return "translator.PushAny(L, "..variable..")"
|
||||
else
|
||||
return "translator.Push(L, "..variable..")"
|
||||
end
|
||||
end
|
||||
|
||||
function GetUpdateStatement(t, idx, variable)
|
||||
if t.IsByRef then t = t:GetElementType() end
|
||||
if typeof(CS.System.Decimal) == t then error('Decimal not update!') end
|
||||
if genPushAndUpdateTypes[t] then
|
||||
return "translator.Update".. CSVariableName(t) .."(L, ".. idx ..", "..variable..")"
|
||||
else
|
||||
return "translator.Update(L, ".. idx ..", "..variable..")"
|
||||
end
|
||||
end
|
||||
|
||||
function JustLuaType(t)
|
||||
return notranslator[getSafeFullName(t)]
|
||||
end
|
||||
|
||||
function CallNeedTranslator(overload, isdelegate)
|
||||
if not overload.IsStatic and not isdelegate then return true end
|
||||
local ret_type_name = getSafeFullName(overload.ReturnType)
|
||||
if not notranslator[ret_type_name] then return true end
|
||||
local parameters = overload:GetParameters()
|
||||
return IfAny(overload:GetParameters(), function(parameter)
|
||||
return IsParams(parameter) or (not notranslator[getSafeFullName(parameter.ParameterType)])
|
||||
end)
|
||||
end
|
||||
|
||||
function MethodCallNeedTranslator(method)
|
||||
return IfAny(method.Overloads, function(overload) return CallNeedTranslator(overload) end)
|
||||
end
|
||||
|
||||
function AccessorNeedTranslator(accessor)
|
||||
return not accessor.IsStatic or not JustLuaType(accessor.Type)
|
||||
end
|
||||
|
||||
function PushObjectNeedTranslator(type_info)
|
||||
return IfAny(type_info.FieldInfos, function(field_info) return not JustLuaType(field_info.Type) end)
|
||||
end
|
||||
|
||||
local GenericParameterAttributes = CS.System.Reflection.GenericParameterAttributes
|
||||
local enum_and_op = debug.getmetatable(CS.System.Reflection.BindingFlags.Public).__band
|
||||
local has_generic_flag = function(f1, f2)
|
||||
return (f1 ~= GenericParameterAttributes.None) and (enum_and_op(f1, f2) == f2)
|
||||
end
|
||||
|
||||
function GenericArgumentList(type)
|
||||
local generic_arg_list = ""
|
||||
local type_constraints = ""
|
||||
if type.IsGenericTypeDefinition then
|
||||
generic_arg_list = "<"
|
||||
|
||||
local constraints = {}
|
||||
|
||||
ForEachCsList(type:GetGenericArguments(), function(generic_arg, gai)
|
||||
local constraint = {}
|
||||
if gai ~= 0 then generic_arg_list = generic_arg_list .. ", " end
|
||||
|
||||
generic_arg_list = generic_arg_list .. generic_arg.Name
|
||||
|
||||
if has_generic_flag(generic_arg.GenericParameterAttributes, GenericParameterAttributes.ReferenceTypeConstraint) then
|
||||
table.insert(constraint, 'class')
|
||||
end
|
||||
if has_generic_flag(generic_arg.GenericParameterAttributes, GenericParameterAttributes.NotNullableValueTypeConstraint) then
|
||||
table.insert(constraint, 'struct')
|
||||
end
|
||||
ForEachCsList(generic_arg:GetGenericParameterConstraints(), function(gpc)
|
||||
if gpc ~= typeof(CS.System.ValueType) or not has_generic_flag(generic_arg.GenericParameterAttributes, GenericParameterAttributes.NotNullableValueTypeConstraint) then
|
||||
table.insert(constraint, CsFullTypeName(gpc))
|
||||
end
|
||||
end)
|
||||
if not has_generic_flag(generic_arg.GenericParameterAttributes, GenericParameterAttributes.NotNullableValueTypeConstraint) and has_generic_flag(generic_arg.GenericParameterAttributes, GenericParameterAttributes.DefaultConstructorConstraint) then
|
||||
table.insert(constraint, 'new()')
|
||||
end
|
||||
if #constraint > 0 then
|
||||
table.insert(constraints, 'where ' .. generic_arg.Name .. ' : ' .. table.concat(constraint, ','))
|
||||
end
|
||||
end)
|
||||
generic_arg_list = generic_arg_list .. ">"
|
||||
if #constraints > 0 then
|
||||
type_constraints = table.concat(constraints, ',')
|
||||
end
|
||||
end
|
||||
return generic_arg_list, type_constraints
|
||||
end
|
||||
|
||||
function LocalName(name)
|
||||
return "_" .. name
|
||||
end
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e72a731aeb3c35b48b0094b70172dfb2
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,20 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
namespace XLua
|
||||
{
|
||||
public class TemplateRef : ScriptableObject
|
||||
{
|
||||
public TextAsset LuaClassWrap;
|
||||
public TextAsset LuaClassWrapGCM;
|
||||
public TextAsset LuaDelegateBridge;
|
||||
public TextAsset LuaDelegateWrap;
|
||||
public TextAsset LuaEnumWrap;
|
||||
public TextAsset LuaEnumWrapGCM;
|
||||
public TextAsset LuaInterfaceBridge;
|
||||
public TextAsset LuaRegister;
|
||||
public TextAsset LuaRegisterGCM;
|
||||
public TextAsset LuaWrapPusher;
|
||||
public TextAsset PackUnpack;
|
||||
public TextAsset TemplateCommon;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b058fae1b1c0da4ab60dba22a7301d2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making xLua available.
|
||||
* Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
* http://opensource.org/licenses/MIT
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace XLua
|
||||
{
|
||||
public enum GenFlag
|
||||
{
|
||||
No = 0,
|
||||
[Obsolete("use GCOptimizeAttribute instead")]
|
||||
GCOptimize = 1
|
||||
}
|
||||
|
||||
//如果你要生成Lua调用CSharp的代码,加这个标签
|
||||
public class LuaCallCSharpAttribute : Attribute
|
||||
{
|
||||
GenFlag flag;
|
||||
public GenFlag Flag {
|
||||
get
|
||||
{
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
|
||||
public LuaCallCSharpAttribute(GenFlag flag = GenFlag.No)
|
||||
{
|
||||
this.flag = flag;
|
||||
}
|
||||
}
|
||||
|
||||
//生成CSharp调用Lua,加这标签
|
||||
//[AttributeUsage(AttributeTargets.Delegate | AttributeTargets.Interface)]
|
||||
public class CSharpCallLuaAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
//如果某属性、方法不需要生成,加这个标签
|
||||
public class BlackListAttribute : Attribute
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum OptimizeFlag
|
||||
{
|
||||
Default = 0,
|
||||
PackAsTable = 1
|
||||
}
|
||||
|
||||
//如果想对struct生成免GC代码,加这个标签
|
||||
public class GCOptimizeAttribute : Attribute
|
||||
{
|
||||
OptimizeFlag flag;
|
||||
public OptimizeFlag Flag
|
||||
{
|
||||
get
|
||||
{
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
|
||||
public GCOptimizeAttribute(OptimizeFlag flag = OptimizeFlag.Default)
|
||||
{
|
||||
this.flag = flag;
|
||||
}
|
||||
}
|
||||
|
||||
//如果想在反射下使用,加这个标签
|
||||
public class ReflectionUseAttribute : Attribute
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//只能标注Dictionary<Type, List<string>>的field或者property
|
||||
public class DoNotGenAttribute : Attribute
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class AdditionalPropertiesAttribute : Attribute
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum HotfixFlag
|
||||
{
|
||||
Stateless = 0,
|
||||
[Obsolete("use xlua.util.state instead!", true)]
|
||||
Stateful = 1,
|
||||
ValueTypeBoxing = 2,
|
||||
IgnoreProperty = 4,
|
||||
IgnoreNotPublic = 8,
|
||||
Inline = 16,
|
||||
IntKey = 32,
|
||||
AdaptByDelegate = 64,
|
||||
IgnoreCompilerGenerated = 128,
|
||||
NoBaseProxy = 256,
|
||||
}
|
||||
|
||||
public class HotfixAttribute : Attribute
|
||||
{
|
||||
HotfixFlag flag;
|
||||
public HotfixFlag Flag
|
||||
{
|
||||
get
|
||||
{
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
|
||||
public HotfixAttribute(HotfixFlag e = HotfixFlag.Stateless)
|
||||
{
|
||||
flag = e;
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Delegate)]
|
||||
internal class HotfixDelegateAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
#if !XLUA_GENERAL
|
||||
public static class SysGenConfig
|
||||
{
|
||||
[GCOptimize]
|
||||
static List<Type> GCOptimize
|
||||
{
|
||||
get
|
||||
{
|
||||
return new List<Type>() {
|
||||
typeof(UnityEngine.Vector2),
|
||||
typeof(UnityEngine.Vector3),
|
||||
typeof(UnityEngine.Vector4),
|
||||
typeof(UnityEngine.Color),
|
||||
typeof(UnityEngine.Quaternion),
|
||||
typeof(UnityEngine.Ray),
|
||||
typeof(UnityEngine.Bounds),
|
||||
typeof(UnityEngine.Ray2D),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[AdditionalProperties]
|
||||
static Dictionary<Type, List<string>> AdditionalProperties
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Dictionary<Type, List<string>>()
|
||||
{
|
||||
{ typeof(UnityEngine.Ray), new List<string>() { "origin", "direction" } },
|
||||
{ typeof(UnityEngine.Ray2D), new List<string>() { "origin", "direction" } },
|
||||
{ typeof(UnityEngine.Bounds), new List<string>() { "center", "extents" } },
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33f8b68bc7d958140805501a27f3d50b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,255 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making xLua available.
|
||||
* Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
* http://opensource.org/licenses/MIT
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using LuaAPI = XLua.LuaDLL.Lua;
|
||||
|
||||
namespace XLua {
|
||||
public partial class DelegateBridge : DelegateBridgeBase {
|
||||
public void Action() {
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock(luaEnv.luaEnvLock) {
|
||||
#endif
|
||||
var L = luaEnv.L;
|
||||
int oldTop = LuaAPI.lua_gettop(L);
|
||||
int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
int error = LuaAPI.lua_pcall(L, 0, 0, errFunc);
|
||||
if (error != 0)
|
||||
luaEnv.ThrowExceptionFromError(oldTop);
|
||||
LuaAPI.lua_settop(L, oldTop);
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public void Action<T1>(T1 p1) {
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock(luaEnv.luaEnvLock) {
|
||||
#endif
|
||||
var L = luaEnv.L;
|
||||
var translator = luaEnv.translator;
|
||||
int oldTop = LuaAPI.lua_gettop(L);
|
||||
int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
translator.PushByType(L, p1);
|
||||
int error = LuaAPI.lua_pcall(L, 1, 0, errFunc);
|
||||
if (error != 0)
|
||||
luaEnv.ThrowExceptionFromError(oldTop);
|
||||
LuaAPI.lua_settop(L, oldTop);
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public void Action<T1, T2>(T1 p1, T2 p2) {
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock(luaEnv.luaEnvLock) {
|
||||
#endif
|
||||
var L = luaEnv.L;
|
||||
var translator = luaEnv.translator;
|
||||
int oldTop = LuaAPI.lua_gettop(L);
|
||||
int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
translator.PushByType(L, p1);
|
||||
translator.PushByType(L, p2);
|
||||
int error = LuaAPI.lua_pcall(L, 2, 0, errFunc);
|
||||
if (error != 0)
|
||||
luaEnv.ThrowExceptionFromError(oldTop);
|
||||
LuaAPI.lua_settop(L, oldTop);
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public void Action<T1, T2, T3>(T1 p1, T2 p2, T3 p3) {
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock(luaEnv.luaEnvLock) {
|
||||
#endif
|
||||
var L = luaEnv.L;
|
||||
var translator = luaEnv.translator;
|
||||
int oldTop = LuaAPI.lua_gettop(L);
|
||||
int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
translator.PushByType(L, p1);
|
||||
translator.PushByType(L, p2);
|
||||
translator.PushByType(L, p3);
|
||||
int error = LuaAPI.lua_pcall(L, 3, 0, errFunc);
|
||||
if (error != 0)
|
||||
luaEnv.ThrowExceptionFromError(oldTop);
|
||||
LuaAPI.lua_settop(L, oldTop);
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public void Action<T1, T2, T3, T4>(T1 p1, T2 p2, T3 p3, T4 p4) {
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock(luaEnv.luaEnvLock) {
|
||||
#endif
|
||||
var L = luaEnv.L;
|
||||
var translator = luaEnv.translator;
|
||||
int oldTop = LuaAPI.lua_gettop(L);
|
||||
int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
translator.PushByType(L, p1);
|
||||
translator.PushByType(L, p2);
|
||||
translator.PushByType(L, p3);
|
||||
translator.PushByType(L, p4);
|
||||
int error = LuaAPI.lua_pcall(L, 4, 0, errFunc);
|
||||
if (error != 0)
|
||||
luaEnv.ThrowExceptionFromError(oldTop);
|
||||
LuaAPI.lua_settop(L, oldTop);
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
public TResult Func<TResult>() {
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock(luaEnv.luaEnvLock) {
|
||||
#endif
|
||||
var L = luaEnv.L;
|
||||
var translator = luaEnv.translator;
|
||||
int oldTop = LuaAPI.lua_gettop(L);
|
||||
int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
int error = LuaAPI.lua_pcall(L, 0, 1, errFunc);
|
||||
if (error != 0)
|
||||
luaEnv.ThrowExceptionFromError(oldTop);
|
||||
TResult ret;
|
||||
try {
|
||||
translator.Get(L, -1, out ret);
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
} finally {
|
||||
LuaAPI.lua_settop(L, oldTop);
|
||||
}
|
||||
return ret;
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public TResult Func<T1, TResult>(T1 p1) {
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock(luaEnv.luaEnvLock) {
|
||||
#endif
|
||||
var L = luaEnv.L;
|
||||
var translator = luaEnv.translator;
|
||||
int oldTop = LuaAPI.lua_gettop(L);
|
||||
int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
translator.PushByType(L, p1);
|
||||
int error = LuaAPI.lua_pcall(L, 1, 1, errFunc);
|
||||
if (error != 0)
|
||||
luaEnv.ThrowExceptionFromError(oldTop);
|
||||
TResult ret;
|
||||
try {
|
||||
translator.Get(L, -1, out ret);
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
} finally {
|
||||
LuaAPI.lua_settop(L, oldTop);
|
||||
}
|
||||
return ret;
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public TResult Func<T1, T2, TResult>(T1 p1, T2 p2) {
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock(luaEnv.luaEnvLock) {
|
||||
#endif
|
||||
var L = luaEnv.L;
|
||||
var translator = luaEnv.translator;
|
||||
int oldTop = LuaAPI.lua_gettop(L);
|
||||
int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
translator.PushByType(L, p1);
|
||||
translator.PushByType(L, p2);
|
||||
int error = LuaAPI.lua_pcall(L, 2, 1, errFunc);
|
||||
if (error != 0)
|
||||
luaEnv.ThrowExceptionFromError(oldTop);
|
||||
TResult ret;
|
||||
try {
|
||||
translator.Get(L, -1, out ret);
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
} finally {
|
||||
LuaAPI.lua_settop(L, oldTop);
|
||||
}
|
||||
return ret;
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public TResult Func<T1, T2, T3, TResult>(T1 p1, T2 p2, T3 p3) {
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock(luaEnv.luaEnvLock) {
|
||||
#endif
|
||||
var L = luaEnv.L;
|
||||
var translator = luaEnv.translator;
|
||||
int oldTop = LuaAPI.lua_gettop(L);
|
||||
int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
translator.PushByType(L, p1);
|
||||
translator.PushByType(L, p2);
|
||||
translator.PushByType(L, p3);
|
||||
int error = LuaAPI.lua_pcall(L, 3, 1, errFunc);
|
||||
if (error != 0)
|
||||
luaEnv.ThrowExceptionFromError(oldTop);
|
||||
TResult ret;
|
||||
try {
|
||||
translator.Get(L, -1, out ret);
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
} finally {
|
||||
LuaAPI.lua_settop(L, oldTop);
|
||||
}
|
||||
return ret;
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public TResult Func<T1, T2, T3, T4, TResult>(T1 p1, T2 p2, T3 p3, T4 p4) {
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock(luaEnv.luaEnvLock) {
|
||||
#endif
|
||||
var L = luaEnv.L;
|
||||
var translator = luaEnv.translator;
|
||||
int oldTop = LuaAPI.lua_gettop(L);
|
||||
int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
translator.PushByType(L, p1);
|
||||
translator.PushByType(L, p2);
|
||||
translator.PushByType(L, p3);
|
||||
translator.PushByType(L, p4);
|
||||
int error = LuaAPI.lua_pcall(L, 4, 1, errFunc);
|
||||
if (error != 0)
|
||||
luaEnv.ThrowExceptionFromError(oldTop);
|
||||
TResult ret;
|
||||
try {
|
||||
translator.Get(L, -1, out ret);
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
} finally {
|
||||
LuaAPI.lua_settop(L, oldTop);
|
||||
}
|
||||
return ret;
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f7c0cbf9beeba44eac9b973c5a4f134
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making xLua available.
|
||||
* Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
* http://opensource.org/licenses/MIT
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
#if USE_UNI_LUA
|
||||
using LuaAPI = UniLua.Lua;
|
||||
using RealStatePtr = UniLua.ILuaState;
|
||||
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
|
||||
#else
|
||||
using LuaAPI = XLua.LuaDLL.Lua;
|
||||
using RealStatePtr = System.IntPtr;
|
||||
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
|
||||
#endif
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace XLua
|
||||
{
|
||||
internal partial class InternalGlobals
|
||||
{
|
||||
#if !THREAD_SAFE && !HOTFIX_ENABLE
|
||||
internal static byte[] strBuff = new byte[256];
|
||||
#endif
|
||||
|
||||
internal delegate bool TryArrayGet(Type type, RealStatePtr L, ObjectTranslator translator, object obj, int index);
|
||||
internal delegate bool TryArraySet(Type type, RealStatePtr L, ObjectTranslator translator, object obj, int array_idx, int obj_idx);
|
||||
internal static volatile TryArrayGet genTryArrayGetPtr = null;
|
||||
internal static volatile TryArraySet genTryArraySetPtr = null;
|
||||
|
||||
internal static volatile ObjectTranslatorPool objectTranslatorPool = new ObjectTranslatorPool();
|
||||
|
||||
internal static volatile int LUA_REGISTRYINDEX = -10000;
|
||||
|
||||
internal static volatile Dictionary<string, string> supportOp = new Dictionary<string, string>()
|
||||
{
|
||||
{ "op_Addition", "__add" },
|
||||
{ "op_Subtraction", "__sub" },
|
||||
{ "op_Multiply", "__mul" },
|
||||
{ "op_Division", "__div" },
|
||||
{ "op_Equality", "__eq" },
|
||||
{ "op_UnaryNegation", "__unm" },
|
||||
{ "op_LessThan", "__lt" },
|
||||
{ "op_LessThanOrEqual", "__le" },
|
||||
{ "op_Modulus", "__mod" },
|
||||
{ "op_BitwiseAnd", "__band" },
|
||||
{ "op_BitwiseOr", "__bor" },
|
||||
{ "op_ExclusiveOr", "__bxor" },
|
||||
{ "op_OnesComplement", "__bnot" },
|
||||
{ "op_LeftShift", "__shl" },
|
||||
{ "op_RightShift", "__shr" },
|
||||
};
|
||||
|
||||
internal static volatile Dictionary<Type, IEnumerable<MethodInfo>> extensionMethodMap = null;
|
||||
|
||||
#if GEN_CODE_MINIMIZE
|
||||
internal static volatile LuaDLL.CSharpWrapperCaller CSharpWrapperCallerPtr = new LuaDLL.CSharpWrapperCaller(StaticLuaCallbacks.CSharpWrapperCallerImpl);
|
||||
#endif
|
||||
|
||||
internal static volatile LuaCSFunction LazyReflectionWrap = new LuaCSFunction(Utils.LazyReflectionCall);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be0ea014ee0821e478652661da20ab2d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making xLua available.
|
||||
* Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
* http://opensource.org/licenses/MIT
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
#if USE_UNI_LUA
|
||||
using LuaAPI = UniLua.Lua;
|
||||
using RealStatePtr = UniLua.ILuaState;
|
||||
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
|
||||
#else
|
||||
using LuaAPI = XLua.LuaDLL.Lua;
|
||||
using RealStatePtr = System.IntPtr;
|
||||
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
|
||||
#endif
|
||||
|
||||
using System;
|
||||
|
||||
namespace XLua
|
||||
{
|
||||
public abstract class LuaBase : IDisposable
|
||||
{
|
||||
protected bool disposed;
|
||||
protected readonly int luaReference;
|
||||
protected readonly LuaEnv luaEnv;
|
||||
|
||||
#if UNITY_EDITOR || XLUA_GENERAL
|
||||
protected int _errorFuncRef { get { return luaEnv.errorFuncRef; } }
|
||||
protected RealStatePtr _L { get { return luaEnv.L; } }
|
||||
protected ObjectTranslator _translator { get { return luaEnv.translator; } }
|
||||
#endif
|
||||
|
||||
public LuaBase(int reference, LuaEnv luaenv)
|
||||
{
|
||||
luaReference = reference;
|
||||
luaEnv = luaenv;
|
||||
}
|
||||
|
||||
~LuaBase()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
public virtual void Dispose(bool disposeManagedResources)
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
if (luaReference != 0)
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnv.luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
bool is_delegate = this is DelegateBridgeBase;
|
||||
if (disposeManagedResources)
|
||||
{
|
||||
luaEnv.translator.ReleaseLuaBase(luaEnv.L, luaReference, is_delegate);
|
||||
}
|
||||
else //will dispse by LuaEnv.GC
|
||||
{
|
||||
luaEnv.equeueGCAction(new LuaEnv.GCAction { Reference = luaReference, IsDelegate = is_delegate });
|
||||
}
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object o)
|
||||
{
|
||||
if (o != null && this.GetType() == o.GetType())
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnv.luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
LuaBase rhs = (LuaBase)o;
|
||||
var L = luaEnv.L;
|
||||
if (L != rhs.luaEnv.L)
|
||||
return false;
|
||||
int top = LuaAPI.lua_gettop(L);
|
||||
LuaAPI.lua_getref(L, rhs.luaReference);
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
int equal = LuaAPI.lua_rawequal(L, -1, -2);
|
||||
LuaAPI.lua_settop(L, top);
|
||||
return (equal != 0);
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
LuaAPI.lua_getref(luaEnv.L, luaReference);
|
||||
var pointer = LuaAPI.lua_topointer(luaEnv.L, -1);
|
||||
LuaAPI.lua_pop(luaEnv.L, 1);
|
||||
return pointer.ToInt32();
|
||||
}
|
||||
|
||||
internal virtual void push(RealStatePtr L)
|
||||
{
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 28af4970710c43f469e5d37933e651c7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,599 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making xLua available.
|
||||
* Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
* http://opensource.org/licenses/MIT
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
namespace XLua.LuaDLL
|
||||
{
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using XLua;
|
||||
|
||||
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || XLUA_GENERAL || (UNITY_WSA && !UNITY_EDITOR)
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate int lua_CSFunction(IntPtr L);
|
||||
|
||||
#if GEN_CODE_MINIMIZE
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate int CSharpWrapperCaller(IntPtr L, int funcidx, int top);
|
||||
#endif
|
||||
#else
|
||||
public delegate int lua_CSFunction(IntPtr L);
|
||||
|
||||
#if GEN_CODE_MINIMIZE
|
||||
public delegate int CSharpWrapperCaller(IntPtr L, int funcidx, int top);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
public partial class Lua
|
||||
{
|
||||
#if (UNITY_IPHONE || UNITY_TVOS || UNITY_WEBGL || UNITY_SWITCH) && !UNITY_EDITOR
|
||||
const string LUADLL = "__Internal";
|
||||
#else
|
||||
const string LUADLL = "xlua";
|
||||
#endif
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr lua_tothread(IntPtr L, int index);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int xlua_get_lib_version();
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int lua_gc(IntPtr L, LuaGCOptions what, int data);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr lua_getupvalue(IntPtr L, int funcindex, int n);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr lua_setupvalue(IntPtr L, int funcindex, int n);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int lua_pushthread(IntPtr L);
|
||||
|
||||
public static bool lua_isfunction(IntPtr L, int stackPos)
|
||||
{
|
||||
return lua_type(L, stackPos) == LuaTypes.LUA_TFUNCTION;
|
||||
}
|
||||
|
||||
public static bool lua_islightuserdata(IntPtr L, int stackPos)
|
||||
{
|
||||
return lua_type(L, stackPos) == LuaTypes.LUA_TLIGHTUSERDATA;
|
||||
}
|
||||
|
||||
public static bool lua_istable(IntPtr L, int stackPos)
|
||||
{
|
||||
return lua_type(L, stackPos) == LuaTypes.LUA_TTABLE;
|
||||
}
|
||||
|
||||
public static bool lua_isthread(IntPtr L, int stackPos)
|
||||
{
|
||||
return lua_type(L, stackPos) == LuaTypes.LUA_TTHREAD;
|
||||
}
|
||||
|
||||
public static int luaL_error(IntPtr L, string message) //[-0, +1, m]
|
||||
{
|
||||
xlua_csharp_str_error(L, message);
|
||||
return 0;
|
||||
}
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int lua_setfenv(IntPtr L, int stackPos);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr luaL_newstate();
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void lua_close(IntPtr L);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] //[-0, +0, m]
|
||||
public static extern void luaopen_xlua(IntPtr L);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] //[-0, +0, m]
|
||||
public static extern void luaL_openlibs(IntPtr L);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint xlua_objlen(IntPtr L, int stackPos);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void lua_createtable(IntPtr L, int narr, int nrec);//[-0, +0, m]
|
||||
|
||||
public static void lua_newtable(IntPtr L)//[-0, +0, m]
|
||||
{
|
||||
lua_createtable(L, 0, 0);
|
||||
}
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int xlua_getglobal(IntPtr L, string name);//[-1, +0, m]
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int xlua_setglobal(IntPtr L, string name);//[-1, +0, m]
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void xlua_getloaders(IntPtr L);
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern void lua_settop(IntPtr L, int newTop);
|
||||
|
||||
public static void lua_pop(IntPtr L, int amount)
|
||||
{
|
||||
lua_settop(L, -(amount) - 1);
|
||||
}
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void lua_insert(IntPtr L, int newTop);
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern void lua_remove(IntPtr L, int index);
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern int lua_rawget(IntPtr L, int index);
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern void lua_rawset(IntPtr L, int index);//[-2, +0, m]
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern int lua_setmetatable(IntPtr L, int objIndex);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int lua_rawequal(IntPtr L, int index1, int index2);
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern void lua_pushvalue(IntPtr L, int index);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void lua_pushcclosure(IntPtr L, IntPtr fn, int n);//[-n, +1, m]
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern void lua_replace(IntPtr L, int index);
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern int lua_gettop(IntPtr L);
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern LuaTypes lua_type(IntPtr L, int index);
|
||||
|
||||
public static bool lua_isnil(IntPtr L, int index)
|
||||
{
|
||||
return (lua_type(L,index)==LuaTypes.LUA_TNIL);
|
||||
}
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern bool lua_isnumber(IntPtr L, int index);
|
||||
|
||||
public static bool lua_isboolean(IntPtr L, int index)
|
||||
{
|
||||
return lua_type(L,index)==LuaTypes.LUA_TBOOLEAN;
|
||||
}
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern int luaL_ref(IntPtr L, int registryIndex);
|
||||
|
||||
public static int luaL_ref(IntPtr L)//[-1, +0, m]
|
||||
{
|
||||
return luaL_ref(L,LuaIndexes.LUA_REGISTRYINDEX);
|
||||
}
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern void xlua_rawgeti(IntPtr L, int tableIndex, long index);
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern void xlua_rawseti(IntPtr L, int tableIndex, long index);//[-1, +0, m]
|
||||
|
||||
public static void lua_getref(IntPtr L, int reference)
|
||||
{
|
||||
xlua_rawgeti(L,LuaIndexes.LUA_REGISTRYINDEX,reference);
|
||||
}
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int pcall_prepare(IntPtr L, int error_func_ref, int func_ref);
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern void luaL_unref(IntPtr L, int registryIndex, int reference);
|
||||
|
||||
public static void lua_unref(IntPtr L, int reference)
|
||||
{
|
||||
luaL_unref(L,LuaIndexes.LUA_REGISTRYINDEX,reference);
|
||||
}
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern bool lua_isstring(IntPtr L, int index);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool lua_isinteger(IntPtr L, int index);
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern void lua_pushnil(IntPtr L);
|
||||
|
||||
public static void lua_pushstdcallcfunction(IntPtr L, lua_CSFunction function, int n = 0)//[-0, +1, m]
|
||||
{
|
||||
#if XLUA_GENERAL || (UNITY_WSA && !UNITY_EDITOR)
|
||||
GCHandle.Alloc(function);
|
||||
#endif
|
||||
IntPtr fn = Marshal.GetFunctionPointerForDelegate(function);
|
||||
xlua_push_csharp_function(L, fn, n);
|
||||
}
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int xlua_upvalueindex(int n);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int lua_pcall(IntPtr L, int nArgs, int nResults, int errfunc);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern double lua_tonumber(IntPtr L, int index);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int xlua_tointeger(IntPtr L, int index);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint xlua_touint(IntPtr L, int index);
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern bool lua_toboolean(IntPtr L, int index);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr lua_topointer(IntPtr L, int index);
|
||||
|
||||
[DllImport(LUADLL,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr lua_tolstring(IntPtr L, int index, out IntPtr strLen);//[-0, +0, m]
|
||||
|
||||
public static string lua_tostring(IntPtr L, int index)
|
||||
{
|
||||
IntPtr strlen;
|
||||
|
||||
IntPtr str = lua_tolstring(L, index, out strlen);
|
||||
if (str != IntPtr.Zero)
|
||||
{
|
||||
#if XLUA_GENERAL || (UNITY_WSA && !UNITY_EDITOR)
|
||||
int len = strlen.ToInt32();
|
||||
byte[] buffer = new byte[len];
|
||||
Marshal.Copy(str, buffer, 0, len);
|
||||
return Encoding.UTF8.GetString(buffer);
|
||||
#else
|
||||
string ret = Marshal.PtrToStringAnsi(str, strlen.ToInt32());
|
||||
if (ret == null)
|
||||
{
|
||||
int len = strlen.ToInt32();
|
||||
byte[] buffer = new byte[len];
|
||||
Marshal.Copy(str, buffer, 0, len);
|
||||
return Encoding.UTF8.GetString(buffer);
|
||||
}
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr lua_atpanic(IntPtr L, lua_CSFunction panicf);
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern void lua_pushnumber(IntPtr L, double number);
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern void lua_pushboolean(IntPtr L, bool value);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void xlua_pushinteger(IntPtr L, int value);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void xlua_pushuint(IntPtr L, uint value);
|
||||
|
||||
#if NATIVE_LUA_PUSHSTRING
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void lua_pushstring(IntPtr L, string str);
|
||||
#else
|
||||
public static void lua_pushstring(IntPtr L, string str) //业务使用
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
lua_pushnil(L);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if !THREAD_SAFE && !HOTFIX_ENABLE
|
||||
if (Encoding.UTF8.GetByteCount(str) > InternalGlobals.strBuff.Length)
|
||||
{
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(str);
|
||||
xlua_pushlstring(L, bytes, bytes.Length);
|
||||
}
|
||||
else
|
||||
{
|
||||
int bytes_len = Encoding.UTF8.GetBytes(str, 0, str.Length, InternalGlobals.strBuff, 0);
|
||||
xlua_pushlstring(L, InternalGlobals.strBuff, bytes_len);
|
||||
}
|
||||
#else
|
||||
var bytes = Encoding.UTF8.GetBytes(str);
|
||||
xlua_pushlstring(L, bytes, bytes.Length);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void xlua_pushlstring(IntPtr L, byte[] str, int size);
|
||||
|
||||
public static void xlua_pushasciistring(IntPtr L, string str) // for inner use only
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
lua_pushnil(L);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if NATIVE_LUA_PUSHSTRING
|
||||
lua_pushstring(L, str);
|
||||
#else
|
||||
#if !THREAD_SAFE && !HOTFIX_ENABLE
|
||||
int str_len = str.Length;
|
||||
if (InternalGlobals.strBuff.Length < str_len)
|
||||
{
|
||||
InternalGlobals.strBuff = new byte[str_len];
|
||||
}
|
||||
|
||||
int bytes_len = Encoding.UTF8.GetBytes(str, 0, str_len, InternalGlobals.strBuff, 0);
|
||||
xlua_pushlstring(L, InternalGlobals.strBuff, bytes_len);
|
||||
#else
|
||||
var bytes = Encoding.UTF8.GetBytes(str);
|
||||
xlua_pushlstring(L, bytes, bytes.Length);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public static void lua_pushstring(IntPtr L, byte[] str)
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
lua_pushnil(L);
|
||||
}
|
||||
else
|
||||
{
|
||||
xlua_pushlstring(L, str, str.Length);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] lua_tobytes(IntPtr L, int index)//[-0, +0, m]
|
||||
{
|
||||
if (lua_type(L, index) == LuaTypes.LUA_TSTRING)
|
||||
{
|
||||
IntPtr strlen;
|
||||
IntPtr str = lua_tolstring(L, index, out strlen);
|
||||
if (str != IntPtr.Zero)
|
||||
{
|
||||
int buff_len = strlen.ToInt32();
|
||||
byte[] buffer = new byte[buff_len];
|
||||
Marshal.Copy(str, buffer, 0, buff_len);
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern int luaL_newmetatable(IntPtr L, string meta);//[-0, +1, m]
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int xlua_pgettable(IntPtr L, int idx);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int xlua_psettable(IntPtr L, int idx);
|
||||
|
||||
public static void luaL_getmetatable(IntPtr L, string meta)
|
||||
{
|
||||
xlua_pushasciistring(L, meta);
|
||||
lua_rawget(L, LuaIndexes.LUA_REGISTRYINDEX);
|
||||
}
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int xluaL_loadbuffer(IntPtr L, byte[] buff, int size, string name);
|
||||
|
||||
public static int luaL_loadbuffer(IntPtr L, string buff, string name)//[-0, +1, m]
|
||||
{
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(buff);
|
||||
return xluaL_loadbuffer(L, bytes, bytes.Length, name);
|
||||
}
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern int xlua_tocsobj_safe(IntPtr L,int obj);//[-0, +0, m]
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern int xlua_tocsobj_fast(IntPtr L,int obj);
|
||||
|
||||
public static int lua_error(IntPtr L)
|
||||
{
|
||||
xlua_csharp_error(L);
|
||||
return 0;
|
||||
}
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool lua_checkstack(IntPtr L,int extra);//[-0, +0, m]
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern int lua_next(IntPtr L,int index);//[-1, +(2|0), e]
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern void lua_pushlightuserdata(IntPtr L, IntPtr udata);
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern IntPtr xlua_tag();
|
||||
|
||||
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
|
||||
public static extern void luaL_where (IntPtr L, int level);//[-0, +1, m]
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int xlua_tryget_cachedud(IntPtr L, int key, int cache_ref);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void xlua_pushcsobj(IntPtr L, int key, int meta_ref, bool need_cache, int cache_ref);//[-0, +1, m]
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]//[,,m]
|
||||
public static extern int gen_obj_indexer(IntPtr L);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]//[,,m]
|
||||
public static extern int gen_obj_newindexer(IntPtr L);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]//[,,m]
|
||||
public static extern int gen_cls_indexer(IntPtr L);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]//[,,m]
|
||||
public static extern int gen_cls_newindexer(IntPtr L);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]//[,,m]
|
||||
public static extern int get_error_func_ref(IntPtr L);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]//[,,m]
|
||||
public static extern int load_error_func(IntPtr L, int Ref);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int luaopen_i64lib(IntPtr L);//[,,m]
|
||||
|
||||
#if (!UNITY_SWITCH && !UNITY_WEBGL) || UNITY_EDITOR
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int luaopen_socket_core(IntPtr L);//[,,m]
|
||||
#endif
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void lua_pushint64(IntPtr L, long n);//[,,m]
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void lua_pushuint64(IntPtr L, ulong n);//[,,m]
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool lua_isint64(IntPtr L, int idx);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool lua_isuint64(IntPtr L, int idx);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern long lua_toint64(IntPtr L, int idx);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern ulong lua_touint64(IntPtr L, int idx);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void xlua_push_csharp_function(IntPtr L, IntPtr fn, int n);//[-0,+1,m]
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int xlua_csharp_str_error(IntPtr L, string message);//[-0,+1,m]
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]//[-0,+0,m]
|
||||
public static extern int xlua_csharp_error(IntPtr L);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_pack_int8_t(IntPtr buff, int offset, byte field);
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_unpack_int8_t(IntPtr buff, int offset, out byte field);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_pack_int16_t(IntPtr buff, int offset, short field);
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_unpack_int16_t(IntPtr buff, int offset, out short field);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_pack_int32_t(IntPtr buff, int offset, int field);
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_unpack_int32_t(IntPtr buff, int offset, out int field);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_pack_int64_t(IntPtr buff, int offset, long field);
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_unpack_int64_t(IntPtr buff, int offset, out long field);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_pack_float(IntPtr buff, int offset, float field);
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_unpack_float(IntPtr buff, int offset, out float field);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_pack_double(IntPtr buff, int offset, double field);
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_unpack_double(IntPtr buff, int offset, out double field);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr xlua_pushstruct(IntPtr L, uint size, int meta_ref);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void xlua_pushcstable(IntPtr L, uint field_count, int meta_ref);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr lua_touserdata(IntPtr L, int idx);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int xlua_gettypeid(IntPtr L, int idx);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int xlua_get_registry_index();
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int xlua_pgettable_bypath(IntPtr L, int idx, string path);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int xlua_psettable_bypath(IntPtr L, int idx, string path);
|
||||
|
||||
//[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
//public static extern void xlua_pushbuffer(IntPtr L, byte[] buff);
|
||||
|
||||
//对于Unity,仅浮点组成的struct较多,这几个api用于优化这类struct
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_pack_float2(IntPtr buff, int offset, float f1, float f2);
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_unpack_float2(IntPtr buff, int offset, out float f1, out float f2);
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_pack_float3(IntPtr buff, int offset, float f1, float f2, float f3);
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_unpack_float3(IntPtr buff, int offset, out float f1, out float f2, out float f3);
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_pack_float4(IntPtr buff, int offset, float f1, float f2, float f3, float f4);
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_unpack_float4(IntPtr buff, int offset, out float f1, out float f2, out float f3, out float f4);
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_pack_float5(IntPtr buff, int offset, float f1, float f2, float f3, float f4, float f5);
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_unpack_float5(IntPtr buff, int offset, out float f1, out float f2, out float f3, out float f4, out float f5);
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_pack_float6(IntPtr buff, int offset, float f1, float f2, float f3, float f4, float f5, float f6);
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_unpack_float6(IntPtr buff, int offset, out float f1, out float f2, out float f3, out float f4, out float f5, out float f6);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_pack_decimal(IntPtr buff, int offset, ref decimal dec);
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_unpack_decimal(IntPtr buff, int offset, out byte scale, out byte sign, out int hi32, out ulong lo64);
|
||||
|
||||
public static bool xlua_is_eq_str(IntPtr L, int index, string str)
|
||||
{
|
||||
return xlua_is_eq_str(L, index, str, str.Length);
|
||||
}
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool xlua_is_eq_str(IntPtr L, int index, string str, int str_len);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr xlua_gl(IntPtr L);
|
||||
|
||||
#if GEN_CODE_MINIMIZE
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void xlua_set_csharp_wrapper_caller(IntPtr wrapper);
|
||||
|
||||
[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void xlua_push_csharp_wrapper(IntPtr L, int wrapperID);
|
||||
|
||||
public static void xlua_set_csharp_wrapper_caller(CSharpWrapperCaller wrapper_caller)
|
||||
{
|
||||
#if XLUA_GENERAL || (UNITY_WSA && !UNITY_EDITOR)
|
||||
GCHandle.Alloc(wrapper);
|
||||
#endif
|
||||
xlua_set_csharp_wrapper_caller(Marshal.GetFunctionPointerForDelegate(wrapper_caller));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 50d6351d52161cc4e94390dde9383215
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,747 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making xLua available.
|
||||
* Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
* http://opensource.org/licenses/MIT
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
#if USE_UNI_LUA
|
||||
using LuaAPI = UniLua.Lua;
|
||||
using RealStatePtr = UniLua.ILuaState;
|
||||
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
|
||||
#else
|
||||
using LuaAPI = XLua.LuaDLL.Lua;
|
||||
using RealStatePtr = System.IntPtr;
|
||||
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
|
||||
#endif
|
||||
|
||||
|
||||
namespace XLua
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class LuaEnv : IDisposable
|
||||
{
|
||||
public const string CSHARP_NAMESPACE = "xlua_csharp_namespace";
|
||||
public const string MAIN_SHREAD = "xlua_main_thread";
|
||||
|
||||
internal RealStatePtr rawL;
|
||||
|
||||
internal RealStatePtr L
|
||||
{
|
||||
get
|
||||
{
|
||||
if (rawL == RealStatePtr.Zero)
|
||||
{
|
||||
throw new InvalidOperationException("this lua env had disposed!");
|
||||
}
|
||||
return rawL;
|
||||
}
|
||||
}
|
||||
|
||||
private LuaTable _G;
|
||||
|
||||
internal ObjectTranslator translator;
|
||||
|
||||
internal int errorFuncRef = -1;
|
||||
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
internal /*static*/ object luaLock = new object();
|
||||
|
||||
internal object luaEnvLock
|
||||
{
|
||||
get
|
||||
{
|
||||
return luaLock;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
const int LIB_VERSION_EXPECT = 105;
|
||||
|
||||
public LuaEnv()
|
||||
{
|
||||
if (LuaAPI.xlua_get_lib_version() != LIB_VERSION_EXPECT)
|
||||
{
|
||||
throw new InvalidProgramException("wrong lib version expect:"
|
||||
+ LIB_VERSION_EXPECT + " but got:" + LuaAPI.xlua_get_lib_version());
|
||||
}
|
||||
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock(luaEnvLock)
|
||||
#endif
|
||||
{
|
||||
LuaIndexes.LUA_REGISTRYINDEX = LuaAPI.xlua_get_registry_index();
|
||||
#if GEN_CODE_MINIMIZE
|
||||
LuaAPI.xlua_set_csharp_wrapper_caller(InternalGlobals.CSharpWrapperCallerPtr);
|
||||
#endif
|
||||
// Create State
|
||||
rawL = LuaAPI.luaL_newstate();
|
||||
|
||||
//Init Base Libs
|
||||
LuaAPI.luaopen_xlua(rawL);
|
||||
LuaAPI.luaopen_i64lib(rawL);
|
||||
|
||||
translator = new ObjectTranslator(this, rawL);
|
||||
translator.createFunctionMetatable(rawL);
|
||||
translator.OpenLib(rawL);
|
||||
ObjectTranslatorPool.Instance.Add(rawL, translator);
|
||||
|
||||
LuaAPI.lua_atpanic(rawL, StaticLuaCallbacks.Panic);
|
||||
|
||||
#if !XLUA_GENERAL
|
||||
LuaAPI.lua_pushstdcallcfunction(rawL, StaticLuaCallbacks.Print);
|
||||
if (0 != LuaAPI.xlua_setglobal(rawL, "print"))
|
||||
{
|
||||
throw new Exception("call xlua_setglobal fail!");
|
||||
}
|
||||
#endif
|
||||
|
||||
//template engine lib register
|
||||
TemplateEngine.LuaTemplate.OpenLib(rawL);
|
||||
|
||||
AddSearcher(StaticLuaCallbacks.LoadBuiltinLib, 2); // just after the preload searcher
|
||||
AddSearcher(StaticLuaCallbacks.LoadFromCustomLoaders, 3);
|
||||
#if !XLUA_GENERAL
|
||||
AddSearcher(StaticLuaCallbacks.LoadFromResource, 4);
|
||||
AddSearcher(StaticLuaCallbacks.LoadFromStreamingAssetsPath, -1);
|
||||
#endif
|
||||
DoString(init_xlua, "Init");
|
||||
init_xlua = null;
|
||||
|
||||
#if !UNITY_SWITCH || UNITY_EDITOR
|
||||
AddBuildin("socket.core", StaticLuaCallbacks.LoadSocketCore);
|
||||
AddBuildin("socket", StaticLuaCallbacks.LoadSocketCore);
|
||||
#endif
|
||||
|
||||
AddBuildin("CS", StaticLuaCallbacks.LoadCS);
|
||||
|
||||
LuaAPI.lua_newtable(rawL); //metatable of indexs and newindexs functions
|
||||
LuaAPI.xlua_pushasciistring(rawL, "__index");
|
||||
LuaAPI.lua_pushstdcallcfunction(rawL, StaticLuaCallbacks.MetaFuncIndex);
|
||||
LuaAPI.lua_rawset(rawL, -3);
|
||||
|
||||
LuaAPI.xlua_pushasciistring(rawL, Utils.LuaIndexsFieldName);
|
||||
LuaAPI.lua_newtable(rawL);
|
||||
LuaAPI.lua_pushvalue(rawL, -3);
|
||||
LuaAPI.lua_setmetatable(rawL, -2);
|
||||
LuaAPI.lua_rawset(rawL, LuaIndexes.LUA_REGISTRYINDEX);
|
||||
|
||||
LuaAPI.xlua_pushasciistring(rawL, Utils.LuaNewIndexsFieldName);
|
||||
LuaAPI.lua_newtable(rawL);
|
||||
LuaAPI.lua_pushvalue(rawL, -3);
|
||||
LuaAPI.lua_setmetatable(rawL, -2);
|
||||
LuaAPI.lua_rawset(rawL, LuaIndexes.LUA_REGISTRYINDEX);
|
||||
|
||||
LuaAPI.xlua_pushasciistring(rawL, Utils.LuaClassIndexsFieldName);
|
||||
LuaAPI.lua_newtable(rawL);
|
||||
LuaAPI.lua_pushvalue(rawL, -3);
|
||||
LuaAPI.lua_setmetatable(rawL, -2);
|
||||
LuaAPI.lua_rawset(rawL, LuaIndexes.LUA_REGISTRYINDEX);
|
||||
|
||||
LuaAPI.xlua_pushasciistring(rawL, Utils.LuaClassNewIndexsFieldName);
|
||||
LuaAPI.lua_newtable(rawL);
|
||||
LuaAPI.lua_pushvalue(rawL, -3);
|
||||
LuaAPI.lua_setmetatable(rawL, -2);
|
||||
LuaAPI.lua_rawset(rawL, LuaIndexes.LUA_REGISTRYINDEX);
|
||||
|
||||
LuaAPI.lua_pop(rawL, 1); // pop metatable of indexs and newindexs functions
|
||||
|
||||
LuaAPI.xlua_pushasciistring(rawL, MAIN_SHREAD);
|
||||
LuaAPI.lua_pushthread(rawL);
|
||||
LuaAPI.lua_rawset(rawL, LuaIndexes.LUA_REGISTRYINDEX);
|
||||
|
||||
LuaAPI.xlua_pushasciistring(rawL, CSHARP_NAMESPACE);
|
||||
if (0 != LuaAPI.xlua_getglobal(rawL, "CS"))
|
||||
{
|
||||
throw new Exception("get CS fail!");
|
||||
}
|
||||
LuaAPI.lua_rawset(rawL, LuaIndexes.LUA_REGISTRYINDEX);
|
||||
|
||||
#if !XLUA_GENERAL && (!UNITY_WSA || UNITY_EDITOR)
|
||||
translator.Alias(typeof(Type), "System.MonoType");
|
||||
#endif
|
||||
|
||||
if (0 != LuaAPI.xlua_getglobal(rawL, "_G"))
|
||||
{
|
||||
throw new Exception("get _G fail!");
|
||||
}
|
||||
translator.Get(rawL, -1, out _G);
|
||||
LuaAPI.lua_pop(rawL, 1);
|
||||
|
||||
errorFuncRef = LuaAPI.get_error_func_ref(rawL);
|
||||
|
||||
if (initers != null)
|
||||
{
|
||||
for (int i = 0; i < initers.Count; i++)
|
||||
{
|
||||
initers[i](this, translator);
|
||||
}
|
||||
}
|
||||
|
||||
translator.CreateArrayMetatable(rawL);
|
||||
translator.CreateDelegateMetatable(rawL);
|
||||
translator.CreateEnumerablePairs(rawL);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Action<LuaEnv, ObjectTranslator>> initers = null;
|
||||
|
||||
public static void AddIniter(Action<LuaEnv, ObjectTranslator> initer)
|
||||
{
|
||||
if (initers == null)
|
||||
{
|
||||
initers = new List<Action<LuaEnv, ObjectTranslator>>();
|
||||
}
|
||||
initers.Add(initer);
|
||||
}
|
||||
|
||||
public LuaTable Global
|
||||
{
|
||||
get
|
||||
{
|
||||
return _G;
|
||||
}
|
||||
}
|
||||
|
||||
public T LoadString<T>(byte[] chunk, string chunkName = "chunk", LuaTable env = null)
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
if (typeof(T) != typeof(LuaFunction) && !typeof(T).IsSubclassOf(typeof(Delegate)))
|
||||
{
|
||||
throw new InvalidOperationException(typeof(T).Name + " is not a delegate type nor LuaFunction");
|
||||
}
|
||||
var _L = L;
|
||||
int oldTop = LuaAPI.lua_gettop(_L);
|
||||
|
||||
if (LuaAPI.xluaL_loadbuffer(_L, chunk, chunk.Length, chunkName) != 0)
|
||||
ThrowExceptionFromError(oldTop);
|
||||
|
||||
if (env != null)
|
||||
{
|
||||
env.push(_L);
|
||||
LuaAPI.lua_setfenv(_L, -2);
|
||||
}
|
||||
|
||||
T result = (T)translator.GetObject(_L, -1, typeof(T));
|
||||
LuaAPI.lua_settop(_L, oldTop);
|
||||
|
||||
return result;
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public T LoadString<T>(string chunk, string chunkName = "chunk", LuaTable env = null)
|
||||
{
|
||||
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(chunk);
|
||||
return LoadString<T>(bytes, chunkName, env);
|
||||
}
|
||||
|
||||
public LuaFunction LoadString(string chunk, string chunkName = "chunk", LuaTable env = null)
|
||||
{
|
||||
return LoadString<LuaFunction>(chunk, chunkName, env);
|
||||
}
|
||||
|
||||
public object[] DoString(byte[] chunk, string chunkName = "chunk", LuaTable env = null)
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
var _L = L;
|
||||
int oldTop = LuaAPI.lua_gettop(_L);
|
||||
int errFunc = LuaAPI.load_error_func(_L, errorFuncRef);
|
||||
if (LuaAPI.xluaL_loadbuffer(_L, chunk, chunk.Length, chunkName) == 0)
|
||||
{
|
||||
if (env != null)
|
||||
{
|
||||
env.push(_L);
|
||||
LuaAPI.lua_setfenv(_L, -2);
|
||||
}
|
||||
|
||||
if (LuaAPI.lua_pcall(_L, 0, -1, errFunc) == 0)
|
||||
{
|
||||
LuaAPI.lua_remove(_L, errFunc);
|
||||
return translator.popValues(_L, oldTop);
|
||||
}
|
||||
else
|
||||
ThrowExceptionFromError(oldTop);
|
||||
}
|
||||
else
|
||||
ThrowExceptionFromError(oldTop);
|
||||
|
||||
return null;
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public object[] DoString(string chunk, string chunkName = "chunk", LuaTable env = null)
|
||||
{
|
||||
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(chunk);
|
||||
return DoString(bytes, chunkName, env);
|
||||
}
|
||||
|
||||
private void AddSearcher(LuaCSFunction searcher, int index)
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
var _L = L;
|
||||
//insert the loader
|
||||
LuaAPI.xlua_getloaders(_L);
|
||||
if (!LuaAPI.lua_istable(_L, -1))
|
||||
{
|
||||
throw new Exception("Can not set searcher!");
|
||||
}
|
||||
uint len = LuaAPI.xlua_objlen(_L, -1);
|
||||
index = index < 0 ? (int)(len + index + 2) : index;
|
||||
for (int e = (int)len + 1; e > index; e--)
|
||||
{
|
||||
LuaAPI.xlua_rawgeti(_L, -1, e - 1);
|
||||
LuaAPI.xlua_rawseti(_L, -2, e);
|
||||
}
|
||||
LuaAPI.lua_pushstdcallcfunction(_L, searcher);
|
||||
LuaAPI.xlua_rawseti(_L, -2, index);
|
||||
LuaAPI.lua_pop(_L, 1);
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public void Alias(Type type, string alias)
|
||||
{
|
||||
translator.Alias(type, alias);
|
||||
}
|
||||
|
||||
#if !XLUA_GENERAL
|
||||
int last_check_point = 0;
|
||||
|
||||
int max_check_per_tick = 20;
|
||||
|
||||
static bool ObjectValidCheck(object obj)
|
||||
{
|
||||
return (!(obj is UnityEngine.Object)) || ((obj as UnityEngine.Object) != null);
|
||||
}
|
||||
|
||||
Func<object, bool> object_valid_checker = new Func<object, bool>(ObjectValidCheck);
|
||||
#endif
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
var _L = L;
|
||||
lock (refQueue)
|
||||
{
|
||||
while (refQueue.Count > 0)
|
||||
{
|
||||
GCAction gca = refQueue.Dequeue();
|
||||
translator.ReleaseLuaBase(_L, gca.Reference, gca.IsDelegate);
|
||||
}
|
||||
}
|
||||
#if !XLUA_GENERAL
|
||||
last_check_point = translator.objects.Check(last_check_point, max_check_per_tick, object_valid_checker, translator.reverseMap);
|
||||
#endif
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>API
|
||||
public void GC()
|
||||
{
|
||||
Tick();
|
||||
}
|
||||
|
||||
public LuaTable NewTable()
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
var _L = L;
|
||||
int oldTop = LuaAPI.lua_gettop(_L);
|
||||
|
||||
LuaAPI.lua_newtable(_L);
|
||||
LuaTable returnVal = (LuaTable)translator.GetObject(_L, -1, typeof(LuaTable));
|
||||
|
||||
LuaAPI.lua_settop(_L, oldTop);
|
||||
return returnVal;
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private bool disposed = false;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
FullGc();
|
||||
System.GC.Collect();
|
||||
System.GC.WaitForPendingFinalizers();
|
||||
|
||||
Dispose(true);
|
||||
|
||||
System.GC.Collect();
|
||||
System.GC.WaitForPendingFinalizers();
|
||||
}
|
||||
|
||||
public virtual void Dispose(bool dispose)
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
if (disposed) return;
|
||||
Tick();
|
||||
|
||||
if (!translator.AllDelegateBridgeReleased())
|
||||
{
|
||||
throw new InvalidOperationException("try to dispose a LuaEnv with C# callback!");
|
||||
}
|
||||
|
||||
ObjectTranslatorPool.Instance.Remove(L);
|
||||
|
||||
LuaAPI.lua_close(L);
|
||||
translator = null;
|
||||
|
||||
rawL = IntPtr.Zero;
|
||||
|
||||
disposed = true;
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public void ThrowExceptionFromError(int oldTop)
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
object err = translator.GetObject(L, -1);
|
||||
LuaAPI.lua_settop(L, oldTop);
|
||||
|
||||
// A pre-wrapped exception - just rethrow it (stack trace of InnerException will be preserved)
|
||||
Exception ex = err as Exception;
|
||||
if (ex != null) throw ex;
|
||||
|
||||
// A non-wrapped Lua error (best interpreted as a string) - wrap it and throw it
|
||||
if (err == null) err = "Unknown Lua Error";
|
||||
throw new LuaException(err.ToString());
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
internal struct GCAction
|
||||
{
|
||||
public int Reference;
|
||||
public bool IsDelegate;
|
||||
}
|
||||
|
||||
Queue<GCAction> refQueue = new Queue<GCAction>();
|
||||
|
||||
internal void equeueGCAction(GCAction action)
|
||||
{
|
||||
lock (refQueue)
|
||||
{
|
||||
refQueue.Enqueue(action);
|
||||
}
|
||||
}
|
||||
|
||||
private string init_xlua = @"
|
||||
local metatable = {}
|
||||
local rawget = rawget
|
||||
local setmetatable = setmetatable
|
||||
local import_type = xlua.import_type
|
||||
local import_generic_type = xlua.import_generic_type
|
||||
local load_assembly = xlua.load_assembly
|
||||
|
||||
function metatable:__index(key)
|
||||
local fqn = rawget(self,'.fqn')
|
||||
fqn = ((fqn and fqn .. '.') or '') .. key
|
||||
|
||||
local obj = import_type(fqn)
|
||||
|
||||
if obj == nil then
|
||||
-- It might be an assembly, so we load it too.
|
||||
obj = { ['.fqn'] = fqn }
|
||||
setmetatable(obj, metatable)
|
||||
elseif obj == true then
|
||||
return rawget(self, key)
|
||||
end
|
||||
|
||||
-- Cache this lookup
|
||||
rawset(self, key, obj)
|
||||
return obj
|
||||
end
|
||||
|
||||
function metatable:__newindex()
|
||||
error('No such type: ' .. rawget(self,'.fqn'), 2)
|
||||
end
|
||||
|
||||
-- A non-type has been called; e.g. foo = System.Foo()
|
||||
function metatable:__call(...)
|
||||
local n = select('#', ...)
|
||||
local fqn = rawget(self,'.fqn')
|
||||
if n > 0 then
|
||||
local gt = import_generic_type(fqn, ...)
|
||||
if gt then
|
||||
return rawget(CS, gt)
|
||||
end
|
||||
end
|
||||
error('No such type: ' .. fqn, 2)
|
||||
end
|
||||
|
||||
CS = CS or {}
|
||||
setmetatable(CS, metatable)
|
||||
|
||||
typeof = function(t) return t.UnderlyingSystemType end
|
||||
cast = xlua.cast
|
||||
if not setfenv or not getfenv then
|
||||
local function getfunction(level)
|
||||
local info = debug.getinfo(level + 1, 'f')
|
||||
return info and info.func
|
||||
end
|
||||
|
||||
function setfenv(fn, env)
|
||||
if type(fn) == 'number' then fn = getfunction(fn + 1) end
|
||||
local i = 1
|
||||
while true do
|
||||
local name = debug.getupvalue(fn, i)
|
||||
if name == '_ENV' then
|
||||
debug.upvaluejoin(fn, i, (function()
|
||||
return env
|
||||
end), 1)
|
||||
break
|
||||
elseif not name then
|
||||
break
|
||||
end
|
||||
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
return fn
|
||||
end
|
||||
|
||||
function getfenv(fn)
|
||||
if type(fn) == 'number' then fn = getfunction(fn + 1) end
|
||||
local i = 1
|
||||
while true do
|
||||
local name, val = debug.getupvalue(fn, i)
|
||||
if name == '_ENV' then
|
||||
return val
|
||||
elseif not name then
|
||||
break
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
xlua.hotfix = function(cs, field, func)
|
||||
if func == nil then func = false end
|
||||
local tbl = (type(field) == 'table') and field or {[field] = func}
|
||||
for k, v in pairs(tbl) do
|
||||
local cflag = ''
|
||||
if k == '.ctor' then
|
||||
cflag = '_c'
|
||||
k = 'ctor'
|
||||
end
|
||||
local f = type(v) == 'function' and v or nil
|
||||
xlua.access(cs, cflag .. '__Hotfix0_'..k, f) -- at least one
|
||||
pcall(function()
|
||||
for i = 1, 99 do
|
||||
xlua.access(cs, cflag .. '__Hotfix'..i..'_'..k, f)
|
||||
end
|
||||
end)
|
||||
end
|
||||
xlua.private_accessible(cs)
|
||||
end
|
||||
xlua.getmetatable = function(cs)
|
||||
return xlua.metatable_operation(cs)
|
||||
end
|
||||
xlua.setmetatable = function(cs, mt)
|
||||
return xlua.metatable_operation(cs, mt)
|
||||
end
|
||||
xlua.setclass = function(parent, name, impl)
|
||||
impl.UnderlyingSystemType = parent[name].UnderlyingSystemType
|
||||
rawset(parent, name, impl)
|
||||
end
|
||||
|
||||
local base_mt = {
|
||||
__index = function(t, k)
|
||||
local csobj = t['__csobj']
|
||||
local func = csobj['<>xLuaBaseProxy_'..k]
|
||||
return function(_, ...)
|
||||
return func(csobj, ...)
|
||||
end
|
||||
end
|
||||
}
|
||||
base = function(csobj)
|
||||
return setmetatable({__csobj = csobj}, base_mt)
|
||||
end
|
||||
";
|
||||
|
||||
public delegate byte[] CustomLoader(ref string filepath);
|
||||
|
||||
internal List<CustomLoader> customLoaders = new List<CustomLoader>();
|
||||
|
||||
//loader : CustomLoader<65><72> filepath<74><68><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ref<65><66><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>require<72>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ֧<D2AA>ֵ<EFBFBD><D6B5>ԣ<EFBFBD><D4A3><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ·<CAB5><C2B7><EFBFBD><EFBFBD>
|
||||
// <20><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>null<6C><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><DEBA>ʵ<EFBFBD><CAB5>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>UTF8<46><38><EFBFBD><EFBFBD><EFBFBD><EFBFBD>byte[]
|
||||
public void AddLoader(CustomLoader loader)
|
||||
{
|
||||
customLoaders.Add(loader);
|
||||
}
|
||||
|
||||
internal Dictionary<string, LuaCSFunction> buildin_initer = new Dictionary<string, LuaCSFunction>();
|
||||
|
||||
public void AddBuildin(string name, LuaCSFunction initer)
|
||||
{
|
||||
if (!Utils.IsStaticPInvokeCSFunction(initer))
|
||||
{
|
||||
throw new Exception("initer must be static and has MonoPInvokeCallback Attribute!");
|
||||
}
|
||||
buildin_initer.Add(name, initer);
|
||||
}
|
||||
|
||||
//The garbage-collector pause controls how long the collector waits before starting a new cycle.
|
||||
//Larger values make the collector less aggressive. Values smaller than 100 mean the collector
|
||||
//will not wait to start a new cycle. A value of 200 means that the collector waits for the total
|
||||
//memory in use to double before starting a new cycle.
|
||||
public int GcPause
|
||||
{
|
||||
get
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
int val = LuaAPI.lua_gc(L, LuaGCOptions.LUA_GCSETPAUSE, 200);
|
||||
LuaAPI.lua_gc(L, LuaGCOptions.LUA_GCSETPAUSE, val);
|
||||
return val;
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
set
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
LuaAPI.lua_gc(L, LuaGCOptions.LUA_GCSETPAUSE, value);
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
//The step multiplier controls the relative speed of the collector relative to memory allocation.
|
||||
//Larger values make the collector more aggressive but also increase the size of each incremental
|
||||
//step. Values smaller than 100 make the collector too slow and can result in the collector never
|
||||
//finishing a cycle. The default, 200, means that the collector runs at "twice" the speed of memory
|
||||
//allocation.
|
||||
public int GcStepmul
|
||||
{
|
||||
get
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
int val = LuaAPI.lua_gc(L, LuaGCOptions.LUA_GCSETSTEPMUL, 200);
|
||||
LuaAPI.lua_gc(L, LuaGCOptions.LUA_GCSETSTEPMUL, val);
|
||||
return val;
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
set
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
LuaAPI.lua_gc(L, LuaGCOptions.LUA_GCSETSTEPMUL, value);
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public void FullGc()
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
LuaAPI.lua_gc(L, LuaGCOptions.LUA_GCCOLLECT, 0);
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public void StopGc()
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
LuaAPI.lua_gc(L, LuaGCOptions.LUA_GCSTOP, 0);
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public void RestartGc()
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
LuaAPI.lua_gc(L, LuaGCOptions.LUA_GCRESTART, 0);
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public bool GcStep(int data)
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
return LuaAPI.lua_gc(L, LuaGCOptions.LUA_GCSTEP, data) != 0;
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public int Memroy
|
||||
{
|
||||
get
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
return LuaAPI.lua_gc(L, LuaGCOptions.LUA_GCCOUNT, 0);
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 931a70d2906f4804ca48c602919411d2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making xLua available.
|
||||
* Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
* http://opensource.org/licenses/MIT
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace XLua
|
||||
{
|
||||
[Serializable]
|
||||
public class LuaException : Exception
|
||||
{
|
||||
public LuaException(string message) : base(message)
|
||||
{}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed0557bcaaf455d458a8388755b597f5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making xLua available.
|
||||
* Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
|
||||
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||||
* http://opensource.org/licenses/MIT
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
#if USE_UNI_LUA
|
||||
using LuaAPI = UniLua.Lua;
|
||||
using RealStatePtr = UniLua.ILuaState;
|
||||
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
|
||||
#else
|
||||
using LuaAPI = XLua.LuaDLL.Lua;
|
||||
using RealStatePtr = System.IntPtr;
|
||||
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
|
||||
#endif
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace XLua
|
||||
{
|
||||
public partial class LuaFunction : LuaBase
|
||||
{
|
||||
public LuaFunction(int reference, LuaEnv luaenv) : base(reference, luaenv)
|
||||
{
|
||||
}
|
||||
|
||||
//Action和Func是方便使用的无gc api,如果需要用到out,ref参数,建议使用delegate
|
||||
//如果需要其它个数的Action和Func, 这个类声明为partial,可以自己加
|
||||
public void Action<T>(T a)
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnv.luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
var L = luaEnv.L;
|
||||
var translator = luaEnv.translator;
|
||||
int oldTop = LuaAPI.lua_gettop(L);
|
||||
int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
translator.PushByType(L, a);
|
||||
int error = LuaAPI.lua_pcall(L, 1, 0, errFunc);
|
||||
if (error != 0)
|
||||
luaEnv.ThrowExceptionFromError(oldTop);
|
||||
LuaAPI.lua_settop(L, oldTop);
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public TResult Func<T, TResult>(T a)
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnv.luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
var L = luaEnv.L;
|
||||
var translator = luaEnv.translator;
|
||||
int oldTop = LuaAPI.lua_gettop(L);
|
||||
int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
translator.PushByType(L, a);
|
||||
int error = LuaAPI.lua_pcall(L, 1, 1, errFunc);
|
||||
if (error != 0)
|
||||
luaEnv.ThrowExceptionFromError(oldTop);
|
||||
TResult ret;
|
||||
try
|
||||
{
|
||||
translator.Get(L, -1, out ret);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LuaAPI.lua_settop(L, oldTop);
|
||||
}
|
||||
return ret;
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public void Action<T1, T2>(T1 a1, T2 a2)
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnv.luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
var L = luaEnv.L;
|
||||
var translator = luaEnv.translator;
|
||||
int oldTop = LuaAPI.lua_gettop(L);
|
||||
int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
translator.PushByType(L, a1);
|
||||
translator.PushByType(L, a2);
|
||||
int error = LuaAPI.lua_pcall(L, 2, 0, errFunc);
|
||||
if (error != 0)
|
||||
luaEnv.ThrowExceptionFromError(oldTop);
|
||||
LuaAPI.lua_settop(L, oldTop);
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public TResult Func<T1, T2, TResult>(T1 a1, T2 a2)
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnv.luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
var L = luaEnv.L;
|
||||
var translator = luaEnv.translator;
|
||||
int oldTop = LuaAPI.lua_gettop(L);
|
||||
int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
translator.PushByType(L, a1);
|
||||
translator.PushByType(L, a2);
|
||||
int error = LuaAPI.lua_pcall(L, 2, 1, errFunc);
|
||||
if (error != 0)
|
||||
luaEnv.ThrowExceptionFromError(oldTop);
|
||||
TResult ret;
|
||||
try
|
||||
{
|
||||
translator.Get(L, -1, out ret);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LuaAPI.lua_settop(L, oldTop);
|
||||
}
|
||||
return ret;
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//deprecated
|
||||
public object[] Call(object[] args, Type[] returnTypes)
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnv.luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
int nArgs = 0;
|
||||
var L = luaEnv.L;
|
||||
var translator = luaEnv.translator;
|
||||
int oldTop = LuaAPI.lua_gettop(L);
|
||||
|
||||
int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
if (args != null)
|
||||
{
|
||||
nArgs = args.Length;
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
{
|
||||
translator.PushAny(L, args[i]);
|
||||
}
|
||||
}
|
||||
int error = LuaAPI.lua_pcall(L, nArgs, -1, errFunc);
|
||||
if (error != 0)
|
||||
luaEnv.ThrowExceptionFromError(oldTop);
|
||||
|
||||
LuaAPI.lua_remove(L, errFunc);
|
||||
if (returnTypes != null)
|
||||
return translator.popValues(L, oldTop, returnTypes);
|
||||
else
|
||||
return translator.popValues(L, oldTop);
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//deprecated
|
||||
public object[] Call(params object[] args)
|
||||
{
|
||||
return Call(args, null);
|
||||
}
|
||||
|
||||
public T Cast<T>()
|
||||
{
|
||||
if (!typeof(T).IsSubclassOf(typeof(Delegate)))
|
||||
{
|
||||
throw new InvalidOperationException(typeof(T).Name + " is not a delegate type");
|
||||
}
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnv.luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
var L = luaEnv.L;
|
||||
var translator = luaEnv.translator;
|
||||
push(L);
|
||||
T ret = (T)translator.GetObject(L, -1, typeof(T));
|
||||
LuaAPI.lua_pop(luaEnv.L, 1);
|
||||
return ret;
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public void SetEnv(LuaTable env)
|
||||
{
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
lock (luaEnv.luaEnvLock)
|
||||
{
|
||||
#endif
|
||||
var L = luaEnv.L;
|
||||
int oldTop = LuaAPI.lua_gettop(L);
|
||||
push(L);
|
||||
env.push(L);
|
||||
LuaAPI.lua_setfenv(L, -2);
|
||||
LuaAPI.lua_settop(L, oldTop);
|
||||
#if THREAD_SAFE || HOTFIX_ENABLE
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
internal override void push(RealStatePtr L)
|
||||
{
|
||||
LuaAPI.lua_getref(L, luaReference);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "function :" + luaReference;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user