Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
NLua
Commits
5555f5a4
Commit
5555f5a4
authored
Mar 28, 2016
by
Vinicius Jarina
Browse files
Merge pull request #196 from MaxVain/Dev
Dev
parents
3d1553a9
53237d2e
Changes
2
Show whitespace changes
Inline
Side-by-side
Core/NLua/NLua.Net35.csproj
View file @
5555f5a4
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
<DebugType>
full
</DebugType>
<DebugType>
full
</DebugType>
<Optimize>
False
</Optimize>
<Optimize>
False
</Optimize>
<OutputPath>
..\..\Run\Debug\net35\
</OutputPath>
<OutputPath>
..\..\Run\Debug\net35\
</OutputPath>
<DefineConstants>
DEBUG
</DefineConstants>
<DefineConstants>
DEBUG
;NET_3_5
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
<WarningLevel>
4
</WarningLevel>
<TreatWarningsAsErrors>
true
</TreatWarningsAsErrors>
<TreatWarningsAsErrors>
true
</TreatWarningsAsErrors>
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
<DebugType>
none
</DebugType>
<DebugType>
none
</DebugType>
<Optimize>
True
</Optimize>
<Optimize>
True
</Optimize>
<OutputPath>
..\..\Run\Release\net35\
</OutputPath>
<OutputPath>
..\..\Run\Release\net35\
</OutputPath>
<DefineConstants>
RELEASE
</DefineConstants>
<DefineConstants>
RELEASE
;NET_3_5
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
<WarningLevel>
4
</WarningLevel>
<PlatformTarget>
AnyCPU
</PlatformTarget>
<PlatformTarget>
AnyCPU
</PlatformTarget>
...
@@ -35,7 +35,7 @@
...
@@ -35,7 +35,7 @@
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)' == 'DebugKopiLua|AnyCPU'"
>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)' == 'DebugKopiLua|AnyCPU'"
>
<DebugSymbols>
true
</DebugSymbols>
<DebugSymbols>
true
</DebugSymbols>
<OutputPath>
bin\DebugKopiLua\
</OutputPath>
<OutputPath>
bin\DebugKopiLua\
</OutputPath>
<DefineConstants>
DEBUG;USE_KOPILUA
</DefineConstants>
<DefineConstants>
DEBUG;
NET_3_5;
USE_KOPILUA
</DefineConstants>
<TreatWarningsAsErrors>
true
</TreatWarningsAsErrors>
<TreatWarningsAsErrors>
true
</TreatWarningsAsErrors>
<DebugType>
full
</DebugType>
<DebugType>
full
</DebugType>
<PlatformTarget>
AnyCPU
</PlatformTarget>
<PlatformTarget>
AnyCPU
</PlatformTarget>
...
@@ -44,7 +44,7 @@
...
@@ -44,7 +44,7 @@
</PropertyGroup>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)' == 'ReleaseKopiLua|AnyCPU'"
>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)' == 'ReleaseKopiLua|AnyCPU'"
>
<OutputPath>
bin\ReleaseKopiLua\
</OutputPath>
<OutputPath>
bin\ReleaseKopiLua\
</OutputPath>
<DefineConstants>
USE_KOPILUA
</DefineConstants>
<DefineConstants>
NET_3_5;
USE_KOPILUA
</DefineConstants>
</PropertyGroup>
</PropertyGroup>
<PropertyGroup>
<PropertyGroup>
<SignAssembly>
true
</SignAssembly>
<SignAssembly>
true
</SignAssembly>
...
...
Core/NLua/ObjectTranslatorPool.cs
View file @
5555f5a4
using
System
;
using
System
;
#if WINDOWS_PHONE || NET_3_5
using
System.Collections.Generic
;
using
System.Collections.Generic
;
#else
using
System.Collections.Concurrent
;
#endif
/*
/*
* This file is part of NLua.
* This file is part of NLua.
...
@@ -38,7 +42,11 @@ namespace NLua
...
@@ -38,7 +42,11 @@ namespace NLua
internal
class
ObjectTranslatorPool
internal
class
ObjectTranslatorPool
{
{
private
static
volatile
ObjectTranslatorPool
instance
=
new
ObjectTranslatorPool
();
private
static
volatile
ObjectTranslatorPool
instance
=
new
ObjectTranslatorPool
();
#if WINDOWS_PHONE || NET_3_5
private
Dictionary
<
LuaState
,
ObjectTranslator
>
translators
=
new
Dictionary
<
LuaState
,
ObjectTranslator
>();
private
Dictionary
<
LuaState
,
ObjectTranslator
>
translators
=
new
Dictionary
<
LuaState
,
ObjectTranslator
>();
#else
private
ConcurrentDictionary
<
LuaState
,
ObjectTranslator
>
translators
=
new
ConcurrentDictionary
<
LuaState
,
ObjectTranslator
>();
#endif
public
static
ObjectTranslatorPool
Instance
public
static
ObjectTranslatorPool
Instance
{
{
...
@@ -54,29 +62,52 @@ namespace NLua
...
@@ -54,29 +62,52 @@ namespace NLua
public
void
Add
(
LuaState
luaState
,
ObjectTranslator
translator
)
public
void
Add
(
LuaState
luaState
,
ObjectTranslator
translator
)
{
{
translators
.
Add
(
luaState
,
translator
);
#if WINDOWS_PHONE || NET_3_5
lock
(
translators
)
translators
.
Add
(
luaState
,
translator
);
#else
if
(!
translators
.
TryAdd
(
luaState
,
translator
))
throw
new
ArgumentException
(
"An item with the same key has already been added. "
,
"luaState"
);
#endif
}
}
public
ObjectTranslator
Find
(
LuaState
luaState
)
public
ObjectTranslator
Find
(
LuaState
luaState
)
{
{
if
(
translators
.
ContainsKey
(
luaState
))
#if WINDOWS_PHONE || NET_3_5
return
translators
[
luaState
];
lock
(
translators
)
{
#endif
ObjectTranslator
translator
;
if
(!
translators
.
TryGetValue
(
luaState
,
out
translator
))
{
LuaState
main
=
LuaCore
.
LuaNetGetMainState
(
luaState
);
LuaState
main
=
LuaCore
.
LuaNetGetMainState
(
luaState
);
if
(
translators
.
ContainsKey
(
main
))
if
(!
translators
.
TryGetValue
(
main
,
out
translator
))
return
translators
[
main
];
translator
=
null
;
}
return
null
;
return
translator
;
#if WINDOWS_PHONE || NET_3_5
}
#endif
}
}
public
void
Remove
(
LuaState
luaState
)
public
void
Remove
(
LuaState
luaState
)
{
{
#if WINDOWS_PHONE || NET_3_5
lock
(
translators
)
{
if
(!
translators
.
ContainsKey
(
luaState
))
if
(!
translators
.
ContainsKey
(
luaState
))
return
;
return
;
translators
.
Remove
(
luaState
);
translators
.
Remove
(
luaState
);
}
}
#else
ObjectTranslator
translator
;
translators
.
TryRemove
(
luaState
,
out
translator
);
#endif
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment