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
c4730b0c
Commit
c4730b0c
authored
Oct 07, 2012
by
Vinicius Jarina
Browse files
Added ifdefs to compile on iOS device (without System.Reflection.Emit )
parent
9ec29ad2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Core/LuaInterface/GenerateEventAssembly/CodeGeneration.cs
View file @
c4730b0c
...
@@ -26,7 +26,9 @@
...
@@ -26,7 +26,9 @@
using
System
;
using
System
;
using
System.Threading
;
using
System.Threading
;
using
System.Reflection
;
using
System.Reflection
;
#if !MONOTOUCH
using
System.Reflection.Emit
;
using
System.Reflection.Emit
;
#endif
using
System.Collections
;
using
System.Collections
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
LuaInterface.Method
;
using
LuaInterface.Method
;
...
@@ -51,8 +53,10 @@ namespace LuaInterface
...
@@ -51,8 +53,10 @@ namespace LuaInterface
private
Type
delegateParent
=
typeof
(
LuaDelegate
);
private
Type
delegateParent
=
typeof
(
LuaDelegate
);
private
Type
classHelper
=
typeof
(
LuaClassHelper
);
private
Type
classHelper
=
typeof
(
LuaClassHelper
);
private
AssemblyName
assemblyName
;
private
AssemblyName
assemblyName
;
#if !MONOTOUCH
private
AssemblyBuilder
newAssembly
;
private
AssemblyBuilder
newAssembly
;
private
ModuleBuilder
newModule
;
private
ModuleBuilder
newModule
;
#endif
private
int
luaClassNumber
=
1
;
private
int
luaClassNumber
=
1
;
static
CodeGeneration
()
static
CodeGeneration
()
...
@@ -61,12 +65,16 @@ namespace LuaInterface
...
@@ -61,12 +65,16 @@ namespace LuaInterface
private
CodeGeneration
()
private
CodeGeneration
()
{
{
#if MONOTOUCH
throw
new
NotImplementedException
(
" Emit not available on MonoTouch "
);
#else
// Create an assembly name
// Create an assembly name
assemblyName
=
new
AssemblyName
();
assemblyName
=
new
AssemblyName
();
assemblyName
.
Name
=
"LuaInterface_generatedcode"
;
assemblyName
.
Name
=
"LuaInterface_generatedcode"
;
// Create a new assembly with one module.
// Create a new assembly with one module.
newAssembly
=
Thread
.
GetDomain
().
DefineDynamicAssembly
(
assemblyName
,
AssemblyBuilderAccess
.
Run
);
newAssembly
=
Thread
.
GetDomain
().
DefineDynamicAssembly
(
assemblyName
,
AssemblyBuilderAccess
.
Run
);
newModule
=
newAssembly
.
DefineDynamicModule
(
"LuaInterface_generatedcode"
);
newModule
=
newAssembly
.
DefineDynamicModule
(
"LuaInterface_generatedcode"
);
#endif
}
}
/*
/*
...
@@ -82,6 +90,9 @@ namespace LuaInterface
...
@@ -82,6 +90,9 @@ namespace LuaInterface
*/
*/
private
Type
GenerateEvent
(
Type
eventHandlerType
)
private
Type
GenerateEvent
(
Type
eventHandlerType
)
{
{
#if MONOTOUCH
throw
new
NotImplementedException
(
" Emit not available on MonoTouch "
);
#else
string
typeName
;
string
typeName
;
lock
(
this
)
lock
(
this
)
{
{
...
@@ -111,6 +122,7 @@ namespace LuaInterface
...
@@ -111,6 +122,7 @@ namespace LuaInterface
generator
.
Emit
(
OpCodes
.
Ret
);
generator
.
Emit
(
OpCodes
.
Ret
);
// creates the new type
// creates the new type
return
myType
.
CreateType
();
return
myType
.
CreateType
();
#endif
}
}
/*
/*
...
@@ -119,6 +131,9 @@ namespace LuaInterface
...
@@ -119,6 +131,9 @@ namespace LuaInterface
*/
*/
private
Type
GenerateDelegate
(
Type
delegateType
)
private
Type
GenerateDelegate
(
Type
delegateType
)
{
{
#if MONOTOUCH
throw
new
NotImplementedException
(
" Emit not available on MonoTouch "
);
#else
string
typeName
;
string
typeName
;
lock
(
this
)
lock
(
this
)
{
{
...
@@ -288,6 +303,7 @@ namespace LuaInterface
...
@@ -288,6 +303,7 @@ namespace LuaInterface
generator
.
Emit
(
OpCodes
.
Ret
);
generator
.
Emit
(
OpCodes
.
Ret
);
return
myType
.
CreateType
();
// creates the new type
return
myType
.
CreateType
();
// creates the new type
#endif
}
}
/*
/*
...
@@ -296,6 +312,9 @@ namespace LuaInterface
...
@@ -296,6 +312,9 @@ namespace LuaInterface
*/
*/
public
void
GenerateClass
(
Type
klass
,
out
Type
newType
,
out
Type
[][]
returnTypes
)
public
void
GenerateClass
(
Type
klass
,
out
Type
newType
,
out
Type
[][]
returnTypes
)
{
{
#if MONOTOUCH
throw
new
NotImplementedException
(
" Emit not available on MonoTouch "
);
#else
string
typeName
;
string
typeName
;
lock
(
this
)
lock
(
this
)
{
{
...
@@ -364,7 +383,9 @@ namespace LuaInterface
...
@@ -364,7 +383,9 @@ namespace LuaInterface
generator
.
Emit
(
OpCodes
.
Ldfld
,
luaTableField
);
generator
.
Emit
(
OpCodes
.
Ldfld
,
luaTableField
);
generator
.
Emit
(
OpCodes
.
Ret
);
generator
.
Emit
(
OpCodes
.
Ret
);
newType
=
myType
.
CreateType
();
// Creates the type
newType
=
myType
.
CreateType
();
// Creates the type
#endif
}
}
#if !MONOTOUCH
/*
/*
* Generates an overriden implementation of method inside myType that delegates
* Generates an overriden implementation of method inside myType that delegates
...
@@ -375,6 +396,7 @@ namespace LuaInterface
...
@@ -375,6 +396,7 @@ namespace LuaInterface
private
void
GenerateMethod
(
TypeBuilder
myType
,
MethodInfo
method
,
MethodAttributes
attributes
,
int
methodIndex
,
private
void
GenerateMethod
(
TypeBuilder
myType
,
MethodInfo
method
,
MethodAttributes
attributes
,
int
methodIndex
,
FieldInfo
luaTableField
,
FieldInfo
returnTypesField
,
bool
generateBase
,
out
Type
[]
returnTypes
)
FieldInfo
luaTableField
,
FieldInfo
returnTypesField
,
bool
generateBase
,
out
Type
[]
returnTypes
)
{
{
var
paramInfo
=
method
.
GetParameters
();
var
paramInfo
=
method
.
GetParameters
();
var
paramTypes
=
new
Type
[
paramInfo
.
Length
];
var
paramTypes
=
new
Type
[
paramInfo
.
Length
];
var
returnTypesList
=
new
List
<
Type
>();
var
returnTypesList
=
new
List
<
Type
>();
...
@@ -606,13 +628,16 @@ namespace LuaInterface
...
@@ -606,13 +628,16 @@ namespace LuaInterface
generator
.
Emit
(
OpCodes
.
Ret
);
generator
.
Emit
(
OpCodes
.
Ret
);
}
}
#endif
/*
/*
* Gets an event handler for the event type that delegates to the eventHandler Lua function.
* Gets an event handler for the event type that delegates to the eventHandler Lua function.
* Caches the generated type.
* Caches the generated type.
*/
*/
public
LuaEventHandler
GetEvent
(
Type
eventHandlerType
,
LuaFunction
eventHandler
)
public
LuaEventHandler
GetEvent
(
Type
eventHandlerType
,
LuaFunction
eventHandler
)
{
{
#if MONOTOUCH
throw
new
NotImplementedException
(
" Emit not available on MonoTouch "
);
#else
Type
eventConsumerType
;
Type
eventConsumerType
;
if
(
eventHandlerCollection
.
ContainsKey
(
eventHandlerType
))
if
(
eventHandlerCollection
.
ContainsKey
(
eventHandlerType
))
...
@@ -626,6 +651,7 @@ namespace LuaInterface
...
@@ -626,6 +651,7 @@ namespace LuaInterface
var
luaEventHandler
=
(
LuaEventHandler
)
Activator
.
CreateInstance
(
eventConsumerType
);
var
luaEventHandler
=
(
LuaEventHandler
)
Activator
.
CreateInstance
(
eventConsumerType
);
luaEventHandler
.
handler
=
eventHandler
;
luaEventHandler
.
handler
=
eventHandler
;
return
luaEventHandler
;
return
luaEventHandler
;
#endif
}
}
/*
/*
...
@@ -634,6 +660,9 @@ namespace LuaInterface
...
@@ -634,6 +660,9 @@ namespace LuaInterface
*/
*/
public
Delegate
GetDelegate
(
Type
delegateType
,
LuaFunction
luaFunc
)
public
Delegate
GetDelegate
(
Type
delegateType
,
LuaFunction
luaFunc
)
{
{
#if MONOTOUCH
throw
new
NotImplementedException
(
" Emit not available on MonoTouch "
);
#else
var
returnTypes
=
new
List
<
Type
>();
var
returnTypes
=
new
List
<
Type
>();
Type
luaDelegateType
;
Type
luaDelegateType
;
...
@@ -658,6 +687,7 @@ namespace LuaInterface
...
@@ -658,6 +687,7 @@ namespace LuaInterface
luaDelegate
.
function
=
luaFunc
;
luaDelegate
.
function
=
luaFunc
;
luaDelegate
.
returnTypes
=
returnTypes
.
ToArray
();
luaDelegate
.
returnTypes
=
returnTypes
.
ToArray
();
return
Delegate
.
CreateDelegate
(
delegateType
,
luaDelegate
,
"CallFunction"
);
return
Delegate
.
CreateDelegate
(
delegateType
,
luaDelegate
,
"CallFunction"
);
#endif
}
}
/*
/*
...
@@ -668,6 +698,9 @@ namespace LuaInterface
...
@@ -668,6 +698,9 @@ namespace LuaInterface
*/
*/
public
object
GetClassInstance
(
Type
klass
,
LuaTable
luaTable
)
public
object
GetClassInstance
(
Type
klass
,
LuaTable
luaTable
)
{
{
#if MONOTOUCH
throw
new
NotImplementedException
(
" Emit not available on MonoTouch "
);
#else
LuaClassType
luaClassType
;
LuaClassType
luaClassType
;
if
(
classCollection
.
ContainsKey
(
klass
))
if
(
classCollection
.
ContainsKey
(
klass
))
...
@@ -680,6 +713,7 @@ namespace LuaInterface
...
@@ -680,6 +713,7 @@ namespace LuaInterface
}
}
return
Activator
.
CreateInstance
(
luaClassType
.
klass
,
new
object
[]
{
luaTable
,
luaClassType
.
returnTypes
});
return
Activator
.
CreateInstance
(
luaClassType
.
klass
,
new
object
[]
{
luaTable
,
luaClassType
.
returnTypes
});
#endif
}
}
}
}
}
}
\ No newline at end of file
Core/LuaInterface/LuaInterface.IOS.csproj
View file @
c4730b0c
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
<DebugType>
full
</DebugType>
<DebugType>
full
</DebugType>
<Optimize>
False
</Optimize>
<Optimize>
False
</Optimize>
<OutputPath>
bin\Debug
</OutputPath>
<OutputPath>
bin\Debug
</OutputPath>
<DefineConstants>
DEBUG;
</DefineConstants>
<DefineConstants>
DEBUG;
MONOTOUCH
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
<WarningLevel>
4
</WarningLevel>
<ConsolePause>
False
</ConsolePause>
<ConsolePause>
False
</ConsolePause>
...
...
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