new type 'lua_Ctx' for continuation-function contexts (to allow type

to be configurable)
This commit is contained in:
Roberto Ierusalimschy 2014-07-17 10:53:37 -03:00
parent 8bb272a3e3
commit 1aa4f69b51
7 changed files with 63 additions and 42 deletions

6
lapi.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lapi.c,v 2.224 2014/07/15 21:14:49 roberto Exp roberto $
** $Id: lapi.c,v 2.225 2014/07/15 21:26:50 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@ -859,7 +859,7 @@ LUA_API void lua_setuservalue (lua_State *L, int idx) {
"results from function overflow current stack size")
LUA_API void lua_callk (lua_State *L, int nargs, int nresults, int ctx,
LUA_API void lua_callk (lua_State *L, int nargs, int nresults, lua_Ctx ctx,
lua_KFunction k) {
StkId func;
lua_lock(L);
@ -899,7 +899,7 @@ static void f_call (lua_State *L, void *ud) {
LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc,
int ctx, lua_KFunction k) {
lua_Ctx ctx, lua_KFunction k) {
struct CallS c;
int status;
ptrdiff_t func;

View File

@ -1,5 +1,5 @@
/*
** $Id: lbaselib.c,v 1.290 2014/06/30 19:48:08 roberto Exp roberto $
** $Id: lbaselib.c,v 1.291 2014/07/16 13:56:59 roberto Exp roberto $
** Basic library
** See Copyright Notice in lua.h
*/
@ -344,7 +344,7 @@ static int luaB_load (lua_State *L) {
/* }====================================================== */
static int dofilecont (lua_State *L, int d1, int d2) {
static int dofilecont (lua_State *L, int d1, lua_Ctx d2) {
(void)d1; (void)d2; /* only to match 'lua_Kfunction' prototype */
return lua_gettop(L) - 1;
}
@ -395,7 +395,7 @@ static int luaB_select (lua_State *L) {
** 'extra' values (where 'extra' is exactly the number of items to be
** ignored).
*/
static int finishpcall (lua_State *L, int status, int extra) {
static int finishpcall (lua_State *L, int status, lua_Ctx extra) {
if (status != LUA_OK && status != LUA_YIELD) { /* error? */
lua_pushboolean(L, 0); /* first result (false) */
lua_pushvalue(L, -2); /* error message */

5
ldo.c
View File

@ -1,5 +1,5 @@
/*
** $Id: ldo.c,v 2.124 2014/06/30 19:48:08 roberto Exp roberto $
** $Id: ldo.c,v 2.125 2014/07/15 21:26:50 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@ -593,7 +593,8 @@ LUA_API int lua_isyieldable (lua_State *L) {
}
LUA_API int lua_yieldk (lua_State *L, int nresults, int ctx, lua_KFunction k) {
LUA_API int lua_yieldk (lua_State *L, int nresults, lua_Ctx ctx,
lua_KFunction k) {
CallInfo *ci = L->ci;
luai_userstateyield(L, nresults);
lua_lock(L);

View File

@ -1,5 +1,5 @@
/*
** $Id: lstate.h,v 2.106 2014/06/10 19:18:50 roberto Exp roberto $
** $Id: lstate.h,v 2.107 2014/06/12 19:07:30 roberto Exp roberto $
** Global State
** See Copyright Notice in lua.h
*/
@ -71,7 +71,7 @@ typedef struct CallInfo {
struct { /* only for C functions */
lua_KFunction k; /* continuation in case of yields */
ptrdiff_t old_errfunc;
int ctx; /* context info. in case of yields */
lua_Ctx ctx; /* context info. in case of yields */
} c;
} u;
} CallInfo;

View File

@ -1,5 +1,5 @@
/*
** $Id: ltests.c,v 2.174 2014/06/26 17:25:11 roberto Exp roberto $
** $Id: ltests.c,v 2.175 2014/07/16 14:51:36 roberto Exp roberto $
** Internal Module for Debugging of the Lua Implementation
** See Copyright Notice in lua.h
*/
@ -981,7 +981,7 @@ static void pushcode (lua_State *L, int code) {
static int testC (lua_State *L);
static int Cfunck (lua_State *L, int status, int ctx);
static int Cfunck (lua_State *L, int status, lua_Ctx ctx);
/*
** arithmetic operation encoding for 'arith' instruction
@ -1318,7 +1318,7 @@ static int Cfunc (lua_State *L) {
}
static int Cfunck (lua_State *L, int status, int ctx) {
static int Cfunck (lua_State *L, int status, lua_Ctx ctx) {
pushcode(L, status);
lua_setglobal(L, "status");
lua_pushinteger(L, ctx);

60
lua.h
View File

@ -1,5 +1,5 @@
/*
** $Id: lua.h,v 1.307 2014/06/10 17:41:38 roberto Exp roberto $
** $Id: lua.h,v 1.308 2014/06/26 17:25:11 roberto Exp roberto $
** Lua - A Scripting Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file
@ -53,30 +53,6 @@
typedef struct lua_State lua_State;
/*
** Type for C functions registered with Lua
*/
typedef int (*lua_CFunction) (lua_State *L);
/*
** Type for continuation functions
*/
typedef int (*lua_KFunction) (lua_State *L, int status, int ctx);
/*
** functions that read/write blocks when loading/dumping Lua chunks
*/
typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
typedef int (*lua_Writer) (lua_State *L, const void *p, size_t sz, void *ud);
/*
** prototype for memory-allocation functions
*/
typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
/*
** basic types
@ -117,6 +93,34 @@ typedef LUA_INTEGER lua_Integer;
/* unsigned integer type */
typedef LUA_UNSIGNED lua_Unsigned;
/* type for continuation-function contexts */
typedef LUA_CTXT lua_Ctx;
/*
** Type for C functions registered with Lua
*/
typedef int (*lua_CFunction) (lua_State *L);
/*
** Type for continuation functions
*/
typedef int (*lua_KFunction) (lua_State *L, int status, lua_Ctx ctx);
/*
** Type for functions that read/write blocks when loading/dumping Lua chunks
*/
typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
typedef int (*lua_Writer) (lua_State *L, const void *p, size_t sz, void *ud);
/*
** Type for memory-allocation functions
*/
typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
/*
@ -262,12 +266,12 @@ LUA_API void (lua_setuservalue) (lua_State *L, int idx);
/*
** 'load' and 'call' functions (load and run Lua code)
*/
LUA_API void (lua_callk) (lua_State *L, int nargs, int nresults, int ctx,
LUA_API void (lua_callk) (lua_State *L, int nargs, int nresults, lua_Ctx ctx,
lua_KFunction k);
#define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL)
LUA_API int (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,
int ctx, lua_KFunction k);
lua_Ctx ctx, lua_KFunction k);
#define lua_pcall(L,n,r,f) lua_pcallk(L, (n), (r), (f), 0, NULL)
LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
@ -280,7 +284,7 @@ LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data, int strip);
/*
** coroutine functions
*/
LUA_API int (lua_yieldk) (lua_State *L, int nresults, int ctx,
LUA_API int (lua_yieldk) (lua_State *L, int nresults, lua_Ctx ctx,
lua_KFunction k);
#define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL)
LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg);

View File

@ -1,5 +1,5 @@
/*
** $Id: luaconf.h,v 1.208 2014/06/24 17:02:00 roberto Exp roberto $
** $Id: luaconf.h,v 1.209 2014/06/26 18:30:27 roberto Exp roberto $
** Configuration file for Lua
** See Copyright Notice in lua.h
*/
@ -254,6 +254,22 @@
#define LUAI_MAXSHORTLEN 40
/*
@@ LUA_CTXT is the type of the context ('ctx') for continuation functions.
@@ It must be a numerical type; Lua will use 'intptr_t' if available.
*/
#if defined (LUA_USE_C99)
#include <stdint.h>
#if defined (INTPTR_MAX) /* even in C99 this type is optional */
#define LUA_CTXT intptr_t
#endif
#endif
#if !defined(LUA_CTXT)
/* default definition (the nearest thing to 'intptr_t' in C89) */
#define LUA_CTXT ptrdiff_t
#endif
/*
** {==================================================================