~ubuntu-branches/ubuntu/quantal/swig2.0/quantal

« back to all changes in this revision

Viewing changes to Lib/lua/luarun.swg

  • Committer: Package Import Robot
  • Author(s): Stefano Rivera
  • Date: 2012-06-01 17:05:17 UTC
  • mfrom: (1.1.6) (10.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20120601170517-q0ik32ij61i4r6f0
Tags: 2.0.7-2ubuntu1
* Merge from Debian unstable (LP: #1006387). Remaining changes:
  - Drop libchicken-dev from the build-depends (in universe).

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#include <assert.h>  /* for a few sanity tests */
17
17
 
18
18
/* -----------------------------------------------------------------------------
 
19
 * Lua flavors
 
20
 * ----------------------------------------------------------------------------- */
 
21
 
 
22
#define SWIG_LUA_FLAVOR_LUA 1
 
23
#define SWIG_LUA_FLAVOR_ELUA 2
 
24
#define SWIG_LUA_FLAVOR_ELUAC 3
 
25
 
 
26
#if !defined(SWIG_LUA_TARGET)
 
27
# error SWIG_LUA_TARGET not defined
 
28
#endif
 
29
 
 
30
#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
 
31
#  define SWIG_LUA_CONSTTAB_INT(B, C) LSTRKEY(B), LNUMVAL(C)
 
32
#  define SWIG_LUA_CONSTTAB_FLOAT(B, C) LSTRKEY(B), LNUMVAL(C)
 
33
#  define SWIG_LUA_CONSTTAB_STRING(B, C) LSTRKEY(B), LSTRVAL(C)
 
34
#  define SWIG_LUA_CONSTTAB_CHAR(B, C) LSTRKEY(B), LNUMVAL(C)
 
35
#else /* SWIG_LUA_FLAVOR_LUA */
 
36
#  define SWIG_LUA_CONSTTAB_INT(B, C) SWIG_LUA_INT, (char *)B, (long)C, 0, 0, 0
 
37
#  define SWIG_LUA_CONSTTAB_FLOAT(B, C) SWIG_LUA_FLOAT, (char *)B, 0, (double)C, 0, 0
 
38
#  define SWIG_LUA_CONSTTAB_STRING(B, C) SWIG_LUA_STRING, (char *)B, 0, 0, (void *)C, 0
 
39
#  define SWIG_LUA_CONSTTAB_CHAR(B, C) SWIG_LUA_CHAR, (char *)B, (long)C, 0, 0, 0
 
40
#endif
 
41
 
 
42
#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
 
43
#  define LRO_STRVAL(v) {{.p = (char *) v}, LUA_TSTRING}
 
44
#  define LSTRVAL LRO_STRVAL
 
45
#endif
 
46
 
 
47
/* -----------------------------------------------------------------------------
 
48
 * compatibility defines
 
49
 * ----------------------------------------------------------------------------- */
 
50
 
 
51
/* History of Lua C API length functions:  In Lua 5.0 (and before?)
 
52
   there was "lua_strlen".  In Lua 5.1, this was renamed "lua_objlen",
 
53
   but a compatibility define of "lua_strlen" was added.  In Lua 5.2,
 
54
   this function was again renamed, to "lua_rawlen" (to emphasize that
 
55
   it doesn't call the "__len" metamethod), and the compatibility
 
56
   define of lua_strlen was removed.  All SWIG uses have been updated
 
57
   to "lua_rawlen", and we add our own defines of that here for older
 
58
   versions of Lua.  */
 
59
#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 501
 
60
# define lua_rawlen lua_strlen
 
61
#elif LUA_VERSION_NUM == 501
 
62
# define lua_rawlen lua_objlen
 
63
#endif
 
64
 
 
65
 
 
66
/* lua_pushglobaltable is the recommended "future-proof" way to get
 
67
   the global table for Lua 5.2 and later.  Here we define
 
68
   lua_pushglobaltable ourselves for Lua versions before 5.2.  */
 
69
#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502
 
70
# define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX)
 
71
#endif
 
72
 
 
73
 
 
74
/* -----------------------------------------------------------------------------
19
75
 * global swig types
20
76
 * ----------------------------------------------------------------------------- */
21
77
/* Constant table */
181
237
   lua_tostring(L,2));
182
238
*/
183
239
  /* get the metatable */
184
 
  assert(lua_istable(L,1));  /* just in case */
 
240
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
 
241
  assert(lua_isrotable(L,1)); /* just in case */
 
242
#else
 
243
  assert(lua_istable(L,1)); /* default Lua action */
 
244
#endif
185
245
  lua_getmetatable(L,1);  /* get the metatable */
186
 
  assert(lua_istable(L,-1));  /* just in case */
 
246
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
 
247
  assert(lua_isrotable(L,-1));  /* just in case */
 
248
#else
 
249
  assert(lua_istable(L,-1));
 
250
#endif
187
251
  SWIG_Lua_get_table(L,".get");  /* get the .get table */
188
252
  lua_remove(L,3);  /* remove metatable */
 
253
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
 
254
  if (lua_isrotable(L,-1))
 
255
#else
189
256
  if (lua_istable(L,-1))
 
257
#endif
190
258
  {
191
259
    /* look for the key in the .get table */
192
260
    lua_pushvalue(L,2);  /* key */
201
269
  }
202
270
  lua_pop(L,1);  /* remove the .get */
203
271
  lua_pushnil(L);  /* return a nil */
204
 
    return 1;
 
272
  return 1;
205
273
}
206
274
 
207
275
/* the module.set method used for setting linked data */
213
281
  (3) any for the new value
214
282
*/
215
283
  /* get the metatable */
216
 
  assert(lua_istable(L,1));  /* just in case */
 
284
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
 
285
  assert(lua_isrotable(L,1));  /* just in case */
 
286
#else
 
287
  assert(lua_istable(L,1)); /* default Lua action */
 
288
#endif
217
289
  lua_getmetatable(L,1);  /* get the metatable */
218
 
  assert(lua_istable(L,-1));  /* just in case */
 
290
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
 
291
  assert(lua_isrotable(L,-1));  /* just in case */
 
292
#else
 
293
  assert(lua_istable(L,-1));
 
294
#endif
219
295
  SWIG_Lua_get_table(L,".set");  /* get the .set table */
220
296
  lua_remove(L,4);  /* remove metatable */
 
297
#if ((SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC))
 
298
  if (lua_isrotable(L,-1))
 
299
#else
221
300
  if (lua_istable(L,-1))
 
301
#endif
222
302
  {
223
303
    /* look for the key in the .set table */
224
304
    lua_pushvalue(L,2);  /* key */
230
310
      lua_call(L,1,0);
231
311
      return 0;
232
312
    }
 
313
#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) 
 
314
    else {
 
315
      return 0; // Exits stoically if an invalid key is initialized.
 
316
    }
 
317
#endif
233
318
  }
234
319
  lua_settop(L,3);  /* reset back to start */
235
320
  /* we now have the table, key & new value, so just set directly */
237
322
  return 0;
238
323
}
239
324
 
 
325
#if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC))
240
326
/* registering a module in lua. Pushes the module table on the stack. */
241
327
SWIGINTERN void  SWIG_Lua_module_begin(lua_State* L,const char* name)
242
328
{
291
377
  }
292
378
  lua_pop(L,1);       /* tidy stack (remove meta) */
293
379
}
 
380
#endif
294
381
 
295
382
/* adding a function module */
296
383
SWIGINTERN void  SWIG_Lua_module_add_function(lua_State* L,const char* name,lua_CFunction fn)
420
507
  return 0;
421
508
}
422
509
 
 
510
/* the class.__tostring method called by the interpreter and print */
 
511
SWIGINTERN int  SWIG_Lua_class_tostring(lua_State* L)
 
512
{
 
513
/*  there should be 1 param passed in
 
514
  (1) userdata (not the metatable) */
 
515
  assert(lua_isuserdata(L,1));  /* just in case */
 
516
  unsigned long userData = (unsigned long)lua_touserdata(L,1); /* get the userdata address for later */
 
517
  lua_getmetatable(L,1);    /* get the meta table */
 
518
  assert(lua_istable(L,-1));  /* just in case */
 
519
  
 
520
  lua_getfield(L, -1, ".type");
 
521
  const char* className = lua_tostring(L, -1);
 
522
  
 
523
  char output[256];
 
524
  sprintf(output, "<%s userdata: %lX>", className, userData);
 
525
  
 
526
  lua_pushstring(L, (const char*)output);
 
527
  return 1;
 
528
}
 
529
 
 
530
/* to manually disown some userdata */
 
531
SWIGINTERN int  SWIG_Lua_class_disown(lua_State* L)
 
532
{
 
533
/*  there should be 1 params passed in
 
534
  (1) userdata (not the meta table) */
 
535
  swig_lua_userdata* usr;
 
536
  assert(lua_isuserdata(L,-1));  /* just in case */
 
537
  usr=(swig_lua_userdata*)lua_touserdata(L,-1);  /* get it */
 
538
  
 
539
  usr->own = 0; /* clear our ownership */
 
540
  return 0;
 
541
}
 
542
 
423
543
/* gets the swig class registry (or creates it) */
424
544
SWIGINTERN void  SWIG_Lua_get_class_registry(lua_State* L)
425
545
{
545
665
  /* add a table called ".fn" */
546
666
  lua_pushstring(L,".fn");
547
667
  lua_newtable(L);
 
668
  /* add manual disown method */
 
669
  SWIG_Lua_add_function(L,"__disown",SWIG_Lua_class_disown);
548
670
  lua_rawset(L,-3);
549
671
  /* add accessor fns for using the .get,.set&.fn */
550
672
  SWIG_Lua_add_function(L,"__index",SWIG_Lua_class_get);
551
673
  SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_class_set);
552
674
  SWIG_Lua_add_function(L,"__gc",SWIG_Lua_class_destruct);
 
675
  /* add tostring method for better output */
 
676
  SWIG_Lua_add_function(L,"__tostring",SWIG_Lua_class_tostring);
553
677
  /* add it */
554
678
  lua_rawset(L,-3);  /* metatable into registry */
555
679
  lua_pop(L,1);      /* tidy stack (remove registry) */
592
716
  usr->ptr=ptr;  /* set the ptr */
593
717
  usr->type=type;
594
718
  usr->own=own;
 
719
#if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC)
595
720
  _SWIG_Lua_AddMetatable(L,type); /* add metatable */
 
721
#endif
596
722
}
597
723
 
598
724
/* takes a object from the lua stack & converts it into an object of the correct type
705
831
 * global variable support code: class/struct typemap functions
706
832
 * ----------------------------------------------------------------------------- */
707
833
 
 
834
#if ((SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUA) && (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC))
708
835
/* Install Constants */
709
836
SWIGINTERN void
710
837
SWIG_Lua_InstallConstants(lua_State* L, swig_lua_const_info constants[]) {
746
873
    }
747
874
  }
748
875
}
 
876
#endif
749
877
 
750
878
/* -----------------------------------------------------------------------------
751
879
 * executing lua code from within the wrapper