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
Hide whitespace changes
Inline
Side-by-side
Core/NLua/NLua.Net35.csproj
View file @
5555f5a4
...
...
@@ -18,7 +18,7 @@
<DebugType>
full
</DebugType>
<Optimize>
False
</Optimize>
<OutputPath>
..\..\Run\Debug\net35\
</OutputPath>
<DefineConstants>
DEBUG
</DefineConstants>
<DefineConstants>
DEBUG
;NET_3_5
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
<TreatWarningsAsErrors>
true
</TreatWarningsAsErrors>
...
...
@@ -27,7 +27,7 @@
<DebugType>
none
</DebugType>
<Optimize>
True
</Optimize>
<OutputPath>
..\..\Run\Release\net35\
</OutputPath>
<DefineConstants>
RELEASE
</DefineConstants>
<DefineConstants>
RELEASE
;NET_3_5
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
<PlatformTarget>
AnyCPU
</PlatformTarget>
...
...
@@ -35,7 +35,7 @@
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)' == 'DebugKopiLua|AnyCPU'"
>
<DebugSymbols>
true
</DebugSymbols>
<OutputPath>
bin\DebugKopiLua\
</OutputPath>
<DefineConstants>
DEBUG;USE_KOPILUA
</DefineConstants>
<DefineConstants>
DEBUG;
NET_3_5;
USE_KOPILUA
</DefineConstants>
<TreatWarningsAsErrors>
true
</TreatWarningsAsErrors>
<DebugType>
full
</DebugType>
<PlatformTarget>
AnyCPU
</PlatformTarget>
...
...
@@ -44,7 +44,7 @@
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)' == 'ReleaseKopiLua|AnyCPU'"
>
<OutputPath>
bin\ReleaseKopiLua\
</OutputPath>
<DefineConstants>
USE_KOPILUA
</DefineConstants>
<DefineConstants>
NET_3_5;
USE_KOPILUA
</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>
true
</SignAssembly>
...
...
@@ -123,4 +123,4 @@
<ItemGroup>
<None
Include=
"key.snk"
/>
</ItemGroup>
</Project>
\ No newline at end of file
</Project>
Core/NLua/ObjectTranslatorPool.cs
View file @
5555f5a4
using
System
;
#if WINDOWS_PHONE || NET_3_5
using
System.Collections.Generic
;
#else
using
System.Collections.Concurrent
;
#endif
/*
* This file is part of NLua.
...
...
@@ -38,8 +42,12 @@ namespace NLua
internal
class
ObjectTranslatorPool
{
private
static
volatile
ObjectTranslatorPool
instance
=
new
ObjectTranslatorPool
();
#if WINDOWS_PHONE || NET_3_5
private
Dictionary
<
LuaState
,
ObjectTranslator
>
translators
=
new
Dictionary
<
LuaState
,
ObjectTranslator
>();
#else
private
ConcurrentDictionary
<
LuaState
,
ObjectTranslator
>
translators
=
new
ConcurrentDictionary
<
LuaState
,
ObjectTranslator
>();
#endif
public
static
ObjectTranslatorPool
Instance
{
get
...
...
@@ -54,28 +62,51 @@ namespace NLua
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
)
{
if
(
translators
.
ContainsKey
(
luaState
))
return
translators
[
luaState
];
#if WINDOWS_PHONE || NET_3_5
lock
(
translators
)
{
#endif
ObjectTranslator
translator
;
LuaState
main
=
LuaCore
.
LuaNetGetMainState
(
luaState
);
if
(!
translators
.
TryGetValue
(
luaState
,
out
translator
))
{
LuaState
main
=
LuaCore
.
LuaNetGetMainState
(
luaState
);
if
(
translators
.
ContainsKey
(
main
))
return
translators
[
main
];
if
(!
translators
.
TryGetValue
(
main
,
out
translator
))
translator
=
null
;
}
return
null
;
return
translator
;
#if WINDOWS_PHONE || NET_3_5
}
#endif
}
public
void
Remove
(
LuaState
luaState
)
{
if
(!
translators
.
ContainsKey
(
luaState
))
return
;
#if WINDOWS_PHONE || NET_3_5
lock
(
translators
)
{
if
(!
translators
.
ContainsKey
(
luaState
))
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