1 #ifndef LIBRARIES_LUA_H
    2 #define LIBRARIES_LUA_H
    3 
    4 /*
    5   lua.library include
    6   For MorphOS adaptation copyright © 2010-2015 Grzegorz Kraszewski.
    7   For Lua programming language itself see below.
    8 */
    9 
   10 /******************************************************************************
   11 * Copyright (C) 1994-2008 Lua.org, PUC-Rio.  All rights reserved.
   12 *
   13 * Permission is hereby granted, free of charge, to any person obtaining
   14 * a copy of this software and associated documentation files (the
   15 * "Software"), to deal in the Software without restriction, including
   16 * without limitation the rights to use, copy, modify, merge, publish,
   17 * distribute, sublicense, and/or sell copies of the Software, and to
   18 * permit persons to whom the Software is furnished to do so, subject to
   19 * the following conditions:
   20 *
   21 * The above copyright notice and this permission notice shall be
   22 * included in all copies or substantial portions of the Software.
   23 *
   24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   27 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   28 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   29 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   30 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   31 ******************************************************************************/
   32 
   33 #ifndef EXEC_TYPES_H
   34 # include <exec/types.h>
   35 #endif
   36 
   37 #define LUA_VERSION       "Lua 5.1"
   38 #define LUA_RELEASE       "Lua 5.1.4"
   39 #define LUA_VERSION_NUM   501
   40 #define LUA_COPYRIGHT     "Copyright © 1994-2008 Lua.org, PUC-Rio"
   41 #define LUA_AUTHORS       "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
   42 #define LUA_SIGNATURE     "\033Lua"
   43 
   44 /*
   45 ** pseudo-indices
   46 */
   47 
   48 #define LUA_REGISTRYINDEX   (-10000)
   49 #define LUA_ENVIRONINDEX    (-10001)
   50 #define LUA_GLOBALSINDEX    (-10002)
   51 #define LUA_UPVALUEINDEX(i) (LUA_GLOBALSINDEX-(i))
   52 #define LUA_MULTRET         (-1)
   53 
   54 /*
   55 ** thread status; 0 is OK
   56 */
   57 
   58 #define LUA_YIELD      1
   59 #define LUA_ERRRUN     2
   60 #define LUA_ERRSYNTAX  3
   61 #define LUA_ERRMEM     4
   62 #define LUA_ERRERR     5
   63 
   64 /*
   65 ** some types used in API
   66 */
   67 
   68 typedef struct lua_State LuaState;
   69 typedef LONG (*LuaCFunction)(LuaState*);
   70 typedef const char* (*LuaReader)(LuaState*, APTR, LONG*);
   71 typedef int (*LuaWriter)(LuaState*, const APTR, LONG, APTR);
   72 typedef APTR (*LuaAlloc)(APTR, APTR, LONG, LONG);
   73 
   74 #define LUA_READER_MEMORY   (LuaReader)(-1)
   75 #define LUA_READER_FILE     (LuaReader)(-2)
   76 #define LUA_WRITER_MEMORY   (LuaWriter)(-1)
   77 #define LUA_WRITER_FILE     (LuaWriter)(-2)
   78 
   79 /* Used when loading and saving Lua code to memory. */
   80 
   81 struct LuaMemoryData
   82 {
   83 	const char  *Buffer;
   84 	LONG         Length;
   85 };
   86 
   87 
   88 /*
   89 ** basic Lua types
   90 */
   91 
   92 #define LUA_TNONE           (-1)
   93 
   94 #define LUA_TNIL              0
   95 #define LUA_TBOOLEAN          1
   96 #define LUA_TLIGHTUSERDATA    2
   97 #define LUA_TNUMBER           3
   98 #define LUA_TSTRING           4
   99 #define LUA_TTABLE            5
  100 #define LUA_TFUNCTION         6
  101 #define LUA_TUSERDATA         7
  102 #define LUA_TTHREAD           8
  103 
  104 /*
  105 ** minimum Lua stack available to a C function
  106 */
  107 
  108 #define LUA_MINSTACK 20
  109 
  110 /*
  111 ** macros
  112 */
  113 
  114 #define LuaPop(L, n) LuaSetTop(L, -(n)-1)
  115 #define LuaNewTable(L) LuaCreateTable(L, 0, 0)
  116 #define LuaRegister(L, n, f) (LuaPushCFunction(L, (f)), LuaSetGlobal(L, (n)))
  117 #define LuaPushCFunction(L, f) LuaPushCClosure(L, (f), 0)
  118 #define LuaStrLen(L, i) LuaObjLen(L, (i))
  119 #define LuaIsFunction(L, n) (LuaType(L, (n)) == LUA_TFUNCTION)
  120 #define LuaIsTable(L, n) (LuaType(L, (n)) == LUA_TTABLE)
  121 #define LuaIsLightUserData(L, n) (LuaType(L, (n)) == LUA_TLIGHTUSERDATA)
  122 #define LuaIsNil(L, n) (LuaType(L, (n)) == LUA_TNIL)
  123 #define LuaIsBoolean(L, n) (LuaType(L, (n)) == LUA_TBOOLEAN)
  124 #define LuaIsThread(L, n) (LuaType(L, (n)) == LUA_TTHREAD)
  125 #define LuaIsNone(L, n) (LuaType(L, (n)) == LUA_TNONE)
  126 #define LuaIsNoneOrNil(L, n) (LuaType(L, (n)) <= 0)
  127 #define LuaPushLiteral(L, s) (LuaPushLString(L, "" s, (sizeof(s) / sizeof(char)) - 1))
  128 #define LuaSetGlobal(L, s) (LuaSetField(L, LUA_GLOBALSINDEX, (s)))
  129 #define LuaGetGlobal(L, s) (LuaGetField(L, LUA_GLOBALSINDEX, (s)))
  130 #define LuaToString(L, i) (LuaToLString(L, (i), NULL))
  131 #define LuaCheckString(L, n) (LuaCheckLString(L, (n), NULL))
  132 #define LuaOptString(L, n, d) (LuaOptLString(L, (n), (d), NULL))
  133 #define LuaOpt(L, f, n, d) (LuaIsNoneOrNil(L, (n)) ? (d) : f(L, (n)))
  134 
  135 #define LuaArgCheck(L, cond, numarg, extramsg) ((void)((cond) || LuaArgError(L, (numarg), (extramsg))))
  136 
  137 #define LUA_IDSIZE 80
  138 
  139 struct LuaDebug {
  140   LONG event;
  141   const char *name;      /* (n) */
  142   const char *namewhat;  /* (n) `global', `local', `field', `method' */
  143   const char *what;      /* (S) `Lua', `C', `main', `tail' */
  144   const char *source;    /* (S) */
  145   LONG currentline;      /* (l) */
  146   LONG nups;             /* (u) number of upvalues */
  147   LONG linedefined;      /* (S) */
  148   LONG lastlinedefined;  /* (S) */
  149   char short_src[LUA_IDSIZE]; /* (S) */
  150   /* private part */
  151   LONG i_ci;  /* active function */
  152 };
  153 
  154 typedef void (*LuaHook)(LuaState*, struct LuaDebug*);
  155 
  156 /* Debug hook event mask constants. */
  157 
  158 #define LUA_HOOKCALL    0
  159 #define LUA_HOOKRET     1
  160 #define LUA_HOOKLINE    2
  161 #define LUA_HOOKCOUNT   3
  162 #define LUA_HOOKTAILRET 4
  163 
  164 #define LUA_MASKCALL    (1 << LUA_HOOKCALL)
  165 #define LUA_MASKRET     (1 << LUA_HOOKRET)
  166 #define LUA_MASKLINE    (1 << LUA_HOOKLINE)
  167 #define LUA_MASKCOUNT   (1 << LUA_HOOKCOUNT)
  168 
  169 
  170 /* definitions for creating compiled modules (shared libs). */
  171 
  172 typedef struct LuaLibReg
  173 {
  174 	const char   *name;
  175 	LuaCFunction  func;
  176 } LuaLibReg;
  177 
  178 
  179 /* macros used in error reporting, define way of quoting */
  180 /* names of variables.                                   */
  181 
  182 #define LUA_QL(x)         "'" x "'"
  183 #define LUA_QS            LUA_QL("%s")
  184 
  185 
  186 /* garbage collector operations */
  187 
  188 #define LUA_GCSTOP          0
  189 #define LUA_GCRESTART       1
  190 #define LUA_GCCOLLECT       2
  191 #define LUA_GCCOUNT         3
  192 #define LUA_GCCOUNTB        4
  193 #define LUA_GCSTEP          5
  194 #define LUA_GCSETPAUSE      6
  195 #define LUA_GCSETSTEPMUL    7
  196 
  197 
  198 #endif /* LIBRARIES_LUA_H */