Click here to Skip to main content
12,694,568 members (33,495 online)
Click here to Skip to main content


122 bookmarked

Integrating Lua into C++

, 2 Sep 2005 CPOL
An article about embedding the Lua scripting language with C++ objects.
** $Id: llimits.h,v 1.52 2003/02/20 19:33:23 roberto Exp $
** Limits, basic types, and some other `installation-dependent' definitions
** See Copyright Notice in lua.h

#ifndef llimits_h
#define llimits_h

#include <limits.h>
#include <stddef.h>

#include "lua.h"

** try to find number of bits in an integer
#ifndef BITS_INT
/* avoid overflows in comparison */
#if INT_MAX-20 < 32760
#define	BITS_INT	16
#if INT_MAX > 2147483640L
/* machine has at least 32 bits */
#define BITS_INT	32
#error "you must define BITS_INT with number of bits in an integer"

** the following types define integer types for values that may not
** fit in a `small int' (16 bits), but may waste space in a
** `large long' (64 bits). The current definitions should work in
** any machine, but may not be optimal.

/* an unsigned integer to hold hash values */
typedef unsigned int lu_hash;
/* its signed equivalent */
typedef int ls_hash;

/* an unsigned integer big enough to count the total memory used by Lua; */
/* it should be at least as large as size_t */
typedef unsigned long lu_mem;


/* an integer big enough to count the number of strings in use */
typedef long ls_nstr;

/* chars used as small naturals (so that `char' is reserved for characters) */
typedef unsigned char lu_byte;

#define MAX_SIZET	((size_t)(~(size_t)0)-2)

#define MAX_INT (INT_MAX-2)  /* maximum value of an int (-2 for safety) */

** conversion of pointer to integer
** this is for hashing only; there is no problem if the integer
** cannot hold the whole pointer value
#define IntPoint(p)  ((lu_hash)(p))

/* type to ensure maximum alignment */
typedef union { double u; void *s; long l; } L_Umaxalign;
typedef LUSER_ALIGNMENT_T L_Umaxalign;

/* result of `usual argument conversion' over lua_Number */
typedef double l_uacNumber;
typedef LUA_UACNUMBER l_uacNumber;

#ifndef lua_assert
#define lua_assert(c)		/* empty */

#ifndef check_exp
#define check_exp(c,e)	(e)

#ifndef UNUSED
#define UNUSED(x)	((void)(x))	/* to avoid warnings */

#ifndef cast
#define cast(t, exp)	((t)(exp))

** type for virtual-machine instructions
** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
typedef unsigned long Instruction;

/* maximum depth for calls (unsigned short) */
#define LUA_MAXCALLS        4096

** maximum depth for C calls (unsigned short): Not too big, or may
** overflow the C stack...

#define LUA_MAXCCALLS        200

/* maximum size for the C stack */
#define LUA_MAXCSTACK        2048

/* maximum stack for a Lua function */
#define MAXSTACK	250

/* maximum number of variables declared in a function */
#ifndef MAXVARS
#define MAXVARS 200           /* arbitrary limit (<MAXSTACK) */

/* maximum number of upvalues per function */
#define MAXUPVALUES	32

/* maximum number of parameters in a function */
#define MAXPARAMS 100           /* arbitrary limit (<MAXLOCALS) */

/* minimum size for the string table (must be power of 2) */

/* minimum size for string buffer */
#define LUA_MINBUFFER	32

** maximum number of syntactical nested non-terminals: Not too big,
** or may overflow the C stack...


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Technical Lead
South Africa South Africa
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170118.1 | Last Updated 2 Sep 2005
Article Copyright 2005 by RichardS
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid