@@ -238,70 +238,57 @@ public override string ToString()
238
238
239
239
public void InvokeSessionStart ( )
240
240
{
241
- lock ( luaEnv . luaEnvLock )
242
- {
243
- var L = luaEnv . L ;
244
- _stack . Push ( _oldTop ) ;
245
- _oldTop = LuaAPI . lua_gettop ( L ) ;
246
- LuaAPI . load_error_func ( L , luaEnv . errorFuncRef ) ;
247
- LuaAPI . lua_getref ( L , luaReference ) ;
248
- }
241
+ System . Threading . Monitor . Enter ( luaEnv . luaEnvLock ) ;
242
+ var L = luaEnv . L ;
243
+ _stack . Push ( _oldTop ) ;
244
+ _oldTop = LuaAPI . lua_gettop ( L ) ;
245
+ LuaAPI . load_error_func ( L , luaEnv . errorFuncRef ) ;
246
+ LuaAPI . lua_getref ( L , luaReference ) ;
249
247
}
250
248
251
249
public void Invoke ( int nRet )
252
250
{
253
- lock ( luaEnv . luaEnvLock )
251
+ int error = LuaAPI . lua_pcall ( luaEnv . L , LuaAPI . lua_gettop ( luaEnv . L ) - _oldTop - 2 , nRet , _oldTop + 1 ) ;
252
+ if ( error != 0 )
254
253
{
255
- int error = LuaAPI . lua_pcall ( luaEnv . L , LuaAPI . lua_gettop ( luaEnv . L ) - _oldTop - 2 , nRet , _oldTop + 1 ) ;
256
- if ( error != 0 )
257
- {
258
- var lastOldTop = _oldTop ;
259
- InvokeSessionEnd ( ) ;
260
- luaEnv . ThrowExceptionFromError ( lastOldTop ) ;
261
- }
254
+ var lastOldTop = _oldTop ;
255
+ InvokeSessionEnd ( ) ;
256
+ luaEnv . ThrowExceptionFromError ( lastOldTop ) ;
262
257
}
263
258
}
264
259
265
260
public void InvokeSessionEnd ( )
266
261
{
267
- lock ( luaEnv . luaEnvLock )
268
- {
269
- LuaAPI . lua_settop ( luaEnv . L , _oldTop ) ;
270
- }
262
+ LuaAPI . lua_settop ( luaEnv . L , _oldTop ) ;
271
263
_oldTop = _stack . Pop ( ) ;
264
+ System . Threading . Monitor . Exit ( luaEnv . luaEnvLock ) ;
272
265
}
273
266
274
267
public TResult InvokeSessionEndWithResult < TResult > ( )
275
268
{
276
- lock ( luaEnv . luaEnvLock )
269
+ if ( LuaAPI . lua_gettop ( luaEnv . L ) < _oldTop + 2 )
277
270
{
278
- if ( LuaAPI . lua_gettop ( luaEnv . L ) < _oldTop + 2 )
279
- {
280
- InvokeSessionEnd ( ) ;
281
- throw new InvalidOperationException ( "no result!" ) ;
282
- }
271
+ InvokeSessionEnd ( ) ;
272
+ throw new InvalidOperationException ( "no result!" ) ;
273
+ }
283
274
284
- try
285
- {
286
- TResult ret ;
287
- luaEnv . translator . Get ( luaEnv . L , _oldTop + 2 , out ret ) ;
288
- return ret ;
289
- }
290
- finally
291
- {
292
- InvokeSessionEnd ( ) ;
293
- }
275
+ try
276
+ {
277
+ TResult ret ;
278
+ luaEnv . translator . Get ( luaEnv . L , _oldTop + 2 , out ret ) ;
279
+ return ret ;
280
+ }
281
+ finally
282
+ {
283
+ InvokeSessionEnd ( ) ;
294
284
}
295
285
}
296
286
297
287
public void InParam < T > ( T p )
298
288
{
299
289
try
300
290
{
301
- lock ( luaEnv . luaEnvLock )
302
- {
303
- luaEnv . translator . PushByType ( luaEnv . L , p ) ;
304
- }
291
+ luaEnv . translator . PushByType ( luaEnv . L , p ) ;
305
292
}
306
293
catch ( Exception e )
307
294
{
@@ -314,12 +301,9 @@ public void InParams<T>(T[] ps)
314
301
{
315
302
try
316
303
{
317
- lock ( luaEnv . luaEnvLock )
304
+ for ( int i = 0 ; i < ps . Length ; i ++ )
318
305
{
319
- for ( int i = 0 ; i < ps . Length ; i ++ )
320
- {
321
- luaEnv . translator . PushByType < T > ( luaEnv . L , ps [ i ] ) ;
322
- }
306
+ luaEnv . translator . PushByType < T > ( luaEnv . L , ps [ i ] ) ;
323
307
}
324
308
}
325
309
catch ( Exception e )
@@ -332,23 +316,20 @@ public void InParams<T>(T[] ps)
332
316
//pos start from 0
333
317
public void OutParam < TResult > ( int pos , out TResult ret )
334
318
{
335
- lock ( luaEnv . luaEnvLock )
319
+ if ( LuaAPI . lua_gettop ( luaEnv . L ) < _oldTop + 2 + pos )
336
320
{
337
- if ( LuaAPI . lua_gettop ( luaEnv . L ) < _oldTop + 2 + pos )
338
- {
339
- InvokeSessionEnd ( ) ;
340
- throw new InvalidOperationException ( "no result in " + pos ) ;
341
- }
321
+ InvokeSessionEnd ( ) ;
322
+ throw new InvalidOperationException ( "no result in " + pos ) ;
323
+ }
342
324
343
- try
344
- {
345
- luaEnv . translator . Get ( luaEnv . L , _oldTop + 2 + pos , out ret ) ;
346
- }
347
- catch ( Exception e )
348
- {
349
- InvokeSessionEnd ( ) ;
350
- throw e ;
351
- }
325
+ try
326
+ {
327
+ luaEnv . translator . Get ( luaEnv . L , _oldTop + 2 + pos , out ret ) ;
328
+ }
329
+ catch ( Exception e )
330
+ {
331
+ InvokeSessionEnd ( ) ;
332
+ throw e ;
352
333
}
353
334
}
354
335
#endif
0 commit comments