misc/liblua/lstate.h
author Wuzzy <Wuzzy2@mail.ru>
Tue, 07 Aug 2018 01:31:50 +0200
changeset 13625 211a37eb6a29
parent 10017 de822cd3df3a
permissions -rw-r--r--
Use gfMultiWeapon in target practice missions
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     1
/*
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     2
** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     3
** Global State
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     4
** See Copyright Notice in lua.h
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     5
*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     6
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     7
#ifndef lstate_h
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     8
#define lstate_h
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     9
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    10
#include "lua.h"
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    11
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    12
#include "lobject.h"
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    13
#include "ltm.h"
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    14
#include "lzio.h"
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    15
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    16
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    17
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    18
struct lua_longjmp;  /* defined in ldo.c */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    19
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    20
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    21
/* table of globals */
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 2812
diff changeset
    22
#define gt(L)   (&L->l_gt)
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    23
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    24
/* registry */
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 2812
diff changeset
    25
#define registry(L) (&G(L)->l_registry)
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    26
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    27
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    28
/* extra stack space to handle TM calls and some other extras */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    29
#define EXTRA_STACK   5
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    30
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    31
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    32
#define BASIC_CI_SIZE           8
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    33
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    34
#define BASIC_STACK_SIZE        (2*LUA_MINSTACK)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    35
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    36
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    37
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    38
typedef struct stringtable {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    39
  GCObject **hash;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    40
  lu_int32 nuse;  /* number of elements */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    41
  int size;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    42
} stringtable;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    43
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    44
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    45
/*
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    46
** informations about a call
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    47
*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    48
typedef struct CallInfo {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    49
  StkId base;  /* base for this function */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    50
  StkId func;  /* function index in the stack */
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 2812
diff changeset
    51
  StkId top;  /* top for this function */
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    52
  const Instruction *savedpc;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    53
  int nresults;  /* expected number of results from this function */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    54
  int tailcalls;  /* number of tail calls lost under this entry */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    55
} CallInfo;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    56
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    57
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    58
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 2812
diff changeset
    59
#define curr_func(L)    (clvalue(L->ci->func))
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 2812
diff changeset
    60
#define ci_func(ci) (clvalue((ci)->func))
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 2812
diff changeset
    61
#define f_isLua(ci) (!ci_func(ci)->c.isC)
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 2812
diff changeset
    62
#define isLua(ci)   (ttisfunction((ci)->func) && f_isLua(ci))
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    63
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    64
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    65
/*
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    66
** `global state', shared by all threads of this state
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    67
*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    68
typedef struct global_State {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    69
  stringtable strt;  /* hash table for strings */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    70
  lua_Alloc frealloc;  /* function to reallocate memory */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    71
  void *ud;         /* auxiliary data to `frealloc' */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    72
  lu_byte currentwhite;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    73
  lu_byte gcstate;  /* state of garbage collector */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    74
  int sweepstrgc;  /* position of sweep in `strt' */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    75
  GCObject *rootgc;  /* list of all collectable objects */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    76
  GCObject **sweepgc;  /* position of sweep in `rootgc' */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    77
  GCObject *gray;  /* list of gray objects */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    78
  GCObject *grayagain;  /* list of objects to be traversed atomically */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    79
  GCObject *weak;  /* list of weak tables (to be cleared) */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    80
  GCObject *tmudata;  /* last element of list of userdata to be GC */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    81
  Mbuffer buff;  /* temporary buffer for string concatentation */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    82
  lu_mem GCthreshold;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    83
  lu_mem totalbytes;  /* number of bytes currently allocated */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    84
  lu_mem estimate;  /* an estimate of number of bytes actually in use */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    85
  lu_mem gcdept;  /* how much GC is `behind schedule' */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    86
  int gcpause;  /* size of pause between successive GCs */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    87
  int gcstepmul;  /* GC `granularity' */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    88
  lua_CFunction panic;  /* to be called in unprotected errors */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    89
  TValue l_registry;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    90
  struct lua_State *mainthread;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    91
  UpVal uvhead;  /* head of double-linked list of all open upvalues */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    92
  struct Table *mt[NUM_TAGS];  /* metatables for basic types */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    93
  TString *tmname[TM_N];  /* array with tag-method names */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    94
} global_State;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    95
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    96
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    97
/*
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    98
** `per thread' state
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    99
*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   100
struct lua_State {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   101
  CommonHeader;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   102
  lu_byte status;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   103
  StkId top;  /* first free slot in the stack */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   104
  StkId base;  /* base of current function */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   105
  global_State *l_G;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   106
  CallInfo *ci;  /* call info for current function */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   107
  const Instruction *savedpc;  /* `savedpc' of current function */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   108
  StkId stack_last;  /* last free slot in the stack */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   109
  StkId stack;  /* stack base */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   110
  CallInfo *end_ci;  /* points after end of ci array*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   111
  CallInfo *base_ci;  /* array of CallInfo's */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   112
  int stacksize;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   113
  int size_ci;  /* size of array `base_ci' */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   114
  unsigned short nCcalls;  /* number of nested C calls */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   115
  unsigned short baseCcalls;  /* nested C calls when resuming coroutine */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   116
  lu_byte hookmask;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   117
  lu_byte allowhook;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   118
  int basehookcount;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   119
  int hookcount;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   120
  lua_Hook hook;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   121
  TValue l_gt;  /* table of globals */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   122
  TValue env;  /* temporary place for environments */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   123
  GCObject *openupval;  /* list of open upvalues in this stack */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   124
  GCObject *gclist;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   125
  struct lua_longjmp *errorJmp;  /* current error recover point */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   126
  ptrdiff_t errfunc;  /* current error handling function (stack index) */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   127
};
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   128
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   129
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 2812
diff changeset
   130
#define G(L)    (L->l_G)
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   131
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   132
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   133
/*
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   134
** Union of all collectable objects
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   135
*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   136
union GCObject {
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   137
  GCheader gch;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   138
  union TString ts;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   139
  union Udata u;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   140
  union Closure cl;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   141
  struct Table h;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   142
  struct Proto p;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   143
  struct UpVal uv;
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   144
  struct lua_State th;  /* thread */
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   145
};
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   146
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   147
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   148
/* macros to convert a GCObject into a specific value */
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 2812
diff changeset
   149
#define rawgco2ts(o)    check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts))
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 2812
diff changeset
   150
#define gco2ts(o)   (&rawgco2ts(o)->tsv)
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 2812
diff changeset
   151
#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 2812
diff changeset
   152
#define gco2u(o)    (&rawgco2u(o)->uv)
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 2812
diff changeset
   153
#define gco2cl(o)   check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl))
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 2812
diff changeset
   154
#define gco2h(o)    check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 2812
diff changeset
   155
#define gco2p(o)    check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 2812
diff changeset
   156
#define gco2uv(o)   check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   157
#define ngcotouv(o) \
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 2812
diff changeset
   158
    check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv))
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 2812
diff changeset
   159
#define gco2th(o)   check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   160
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   161
/* macro to convert any Lua object into a GCObject */
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 2812
diff changeset
   162
#define obj2gco(v)  (cast(GCObject *, (v)))
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   163
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   164
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   165
LUAI_FUNC lua_State *luaE_newthread (lua_State *L);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   166
LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   167
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   168
#endif
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
   169