diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-07-17 10:53:37 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-07-17 10:53:37 -0300 |
| commit | 1aa4f69b51a92dc4f5c9d35925b9977d35650679 (patch) | |
| tree | d63d6534a52452d1c9f4f0c0e6210f4c0435f769 | |
| parent | 8bb272a3e3d0693a1d587cfa3469153978ae617f (diff) | |
| download | lua-1aa4f69b51a92dc4f5c9d35925b9977d35650679.tar.gz lua-1aa4f69b51a92dc4f5c9d35925b9977d35650679.tar.bz2 lua-1aa4f69b51a92dc4f5c9d35925b9977d35650679.zip | |
new type 'lua_Ctx' for continuation-function contexts (to allow type
to be configurable)
| -rw-r--r-- | lapi.c | 6 | ||||
| -rw-r--r-- | lbaselib.c | 6 | ||||
| -rw-r--r-- | ldo.c | 5 | ||||
| -rw-r--r-- | lstate.h | 4 | ||||
| -rw-r--r-- | ltests.c | 6 | ||||
| -rw-r--r-- | lua.h | 60 | ||||
| -rw-r--r-- | luaconf.h | 18 |
7 files changed, 63 insertions, 42 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.224 2014/07/15 21:14:49 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.225 2014/07/15 21:26:50 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -859,7 +859,7 @@ LUA_API void lua_setuservalue (lua_State *L, int idx) { | |||
| 859 | "results from function overflow current stack size") | 859 | "results from function overflow current stack size") |
| 860 | 860 | ||
| 861 | 861 | ||
| 862 | LUA_API void lua_callk (lua_State *L, int nargs, int nresults, int ctx, | 862 | LUA_API void lua_callk (lua_State *L, int nargs, int nresults, lua_Ctx ctx, |
| 863 | lua_KFunction k) { | 863 | lua_KFunction k) { |
| 864 | StkId func; | 864 | StkId func; |
| 865 | lua_lock(L); | 865 | lua_lock(L); |
| @@ -899,7 +899,7 @@ static void f_call (lua_State *L, void *ud) { | |||
| 899 | 899 | ||
| 900 | 900 | ||
| 901 | LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc, | 901 | LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc, |
| 902 | int ctx, lua_KFunction k) { | 902 | lua_Ctx ctx, lua_KFunction k) { |
| 903 | struct CallS c; | 903 | struct CallS c; |
| 904 | int status; | 904 | int status; |
| 905 | ptrdiff_t func; | 905 | ptrdiff_t func; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.290 2014/06/30 19:48:08 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.291 2014/07/16 13:56:59 roberto Exp roberto $ |
| 3 | ** Basic library | 3 | ** Basic library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -344,7 +344,7 @@ static int luaB_load (lua_State *L) { | |||
| 344 | /* }====================================================== */ | 344 | /* }====================================================== */ |
| 345 | 345 | ||
| 346 | 346 | ||
| 347 | static int dofilecont (lua_State *L, int d1, int d2) { | 347 | static int dofilecont (lua_State *L, int d1, lua_Ctx d2) { |
| 348 | (void)d1; (void)d2; /* only to match 'lua_Kfunction' prototype */ | 348 | (void)d1; (void)d2; /* only to match 'lua_Kfunction' prototype */ |
| 349 | return lua_gettop(L) - 1; | 349 | return lua_gettop(L) - 1; |
| 350 | } | 350 | } |
| @@ -395,7 +395,7 @@ static int luaB_select (lua_State *L) { | |||
| 395 | ** 'extra' values (where 'extra' is exactly the number of items to be | 395 | ** 'extra' values (where 'extra' is exactly the number of items to be |
| 396 | ** ignored). | 396 | ** ignored). |
| 397 | */ | 397 | */ |
| 398 | static int finishpcall (lua_State *L, int status, int extra) { | 398 | static int finishpcall (lua_State *L, int status, lua_Ctx extra) { |
| 399 | if (status != LUA_OK && status != LUA_YIELD) { /* error? */ | 399 | if (status != LUA_OK && status != LUA_YIELD) { /* error? */ |
| 400 | lua_pushboolean(L, 0); /* first result (false) */ | 400 | lua_pushboolean(L, 0); /* first result (false) */ |
| 401 | lua_pushvalue(L, -2); /* error message */ | 401 | lua_pushvalue(L, -2); /* error message */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 2.124 2014/06/30 19:48:08 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.125 2014/07/15 21:26:50 roberto Exp roberto $ |
| 3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -593,7 +593,8 @@ LUA_API int lua_isyieldable (lua_State *L) { | |||
| 593 | } | 593 | } |
| 594 | 594 | ||
| 595 | 595 | ||
| 596 | LUA_API int lua_yieldk (lua_State *L, int nresults, int ctx, lua_KFunction k) { | 596 | LUA_API int lua_yieldk (lua_State *L, int nresults, lua_Ctx ctx, |
| 597 | lua_KFunction k) { | ||
| 597 | CallInfo *ci = L->ci; | 598 | CallInfo *ci = L->ci; |
| 598 | luai_userstateyield(L, nresults); | 599 | luai_userstateyield(L, nresults); |
| 599 | lua_lock(L); | 600 | lua_lock(L); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstate.h,v 2.106 2014/06/10 19:18:50 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 2.107 2014/06/12 19:07:30 roberto Exp roberto $ |
| 3 | ** Global State | 3 | ** Global State |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -71,7 +71,7 @@ typedef struct CallInfo { | |||
| 71 | struct { /* only for C functions */ | 71 | struct { /* only for C functions */ |
| 72 | lua_KFunction k; /* continuation in case of yields */ | 72 | lua_KFunction k; /* continuation in case of yields */ |
| 73 | ptrdiff_t old_errfunc; | 73 | ptrdiff_t old_errfunc; |
| 74 | int ctx; /* context info. in case of yields */ | 74 | lua_Ctx ctx; /* context info. in case of yields */ |
| 75 | } c; | 75 | } c; |
| 76 | } u; | 76 | } u; |
| 77 | } CallInfo; | 77 | } CallInfo; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 2.174 2014/06/26 17:25:11 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.175 2014/07/16 14:51:36 roberto Exp roberto $ |
| 3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -981,7 +981,7 @@ static void pushcode (lua_State *L, int code) { | |||
| 981 | 981 | ||
| 982 | 982 | ||
| 983 | static int testC (lua_State *L); | 983 | static int testC (lua_State *L); |
| 984 | static int Cfunck (lua_State *L, int status, int ctx); | 984 | static int Cfunck (lua_State *L, int status, lua_Ctx ctx); |
| 985 | 985 | ||
| 986 | /* | 986 | /* |
| 987 | ** arithmetic operation encoding for 'arith' instruction | 987 | ** arithmetic operation encoding for 'arith' instruction |
| @@ -1318,7 +1318,7 @@ static int Cfunc (lua_State *L) { | |||
| 1318 | } | 1318 | } |
| 1319 | 1319 | ||
| 1320 | 1320 | ||
| 1321 | static int Cfunck (lua_State *L, int status, int ctx) { | 1321 | static int Cfunck (lua_State *L, int status, lua_Ctx ctx) { |
| 1322 | pushcode(L, status); | 1322 | pushcode(L, status); |
| 1323 | lua_setglobal(L, "status"); | 1323 | lua_setglobal(L, "status"); |
| 1324 | lua_pushinteger(L, ctx); | 1324 | lua_pushinteger(L, ctx); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.h,v 1.307 2014/06/10 17:41:38 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.308 2014/06/26 17:25:11 roberto Exp roberto $ |
| 3 | ** Lua - A Scripting Language | 3 | ** Lua - A Scripting Language |
| 4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) | 4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) |
| 5 | ** See Copyright Notice at the end of this file | 5 | ** See Copyright Notice at the end of this file |
| @@ -53,30 +53,6 @@ | |||
| 53 | 53 | ||
| 54 | typedef struct lua_State lua_State; | 54 | typedef struct lua_State lua_State; |
| 55 | 55 | ||
| 56 | /* | ||
| 57 | ** Type for C functions registered with Lua | ||
| 58 | */ | ||
| 59 | typedef int (*lua_CFunction) (lua_State *L); | ||
| 60 | |||
| 61 | /* | ||
| 62 | ** Type for continuation functions | ||
| 63 | */ | ||
| 64 | typedef int (*lua_KFunction) (lua_State *L, int status, int ctx); | ||
| 65 | |||
| 66 | |||
| 67 | /* | ||
| 68 | ** functions that read/write blocks when loading/dumping Lua chunks | ||
| 69 | */ | ||
| 70 | typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz); | ||
| 71 | |||
| 72 | typedef int (*lua_Writer) (lua_State *L, const void *p, size_t sz, void *ud); | ||
| 73 | |||
| 74 | |||
| 75 | /* | ||
| 76 | ** prototype for memory-allocation functions | ||
| 77 | */ | ||
| 78 | typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); | ||
| 79 | |||
| 80 | 56 | ||
| 81 | /* | 57 | /* |
| 82 | ** basic types | 58 | ** basic types |
| @@ -117,6 +93,34 @@ typedef LUA_INTEGER lua_Integer; | |||
| 117 | /* unsigned integer type */ | 93 | /* unsigned integer type */ |
| 118 | typedef LUA_UNSIGNED lua_Unsigned; | 94 | typedef LUA_UNSIGNED lua_Unsigned; |
| 119 | 95 | ||
| 96 | /* type for continuation-function contexts */ | ||
| 97 | typedef LUA_CTXT lua_Ctx; | ||
| 98 | |||
| 99 | |||
| 100 | /* | ||
| 101 | ** Type for C functions registered with Lua | ||
| 102 | */ | ||
| 103 | typedef int (*lua_CFunction) (lua_State *L); | ||
| 104 | |||
| 105 | /* | ||
| 106 | ** Type for continuation functions | ||
| 107 | */ | ||
| 108 | typedef int (*lua_KFunction) (lua_State *L, int status, lua_Ctx ctx); | ||
| 109 | |||
| 110 | |||
| 111 | /* | ||
| 112 | ** Type for functions that read/write blocks when loading/dumping Lua chunks | ||
| 113 | */ | ||
| 114 | typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz); | ||
| 115 | |||
| 116 | typedef int (*lua_Writer) (lua_State *L, const void *p, size_t sz, void *ud); | ||
| 117 | |||
| 118 | |||
| 119 | /* | ||
| 120 | ** Type for memory-allocation functions | ||
| 121 | */ | ||
| 122 | typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); | ||
| 123 | |||
| 120 | 124 | ||
| 121 | 125 | ||
| 122 | /* | 126 | /* |
| @@ -262,12 +266,12 @@ LUA_API void (lua_setuservalue) (lua_State *L, int idx); | |||
| 262 | /* | 266 | /* |
| 263 | ** 'load' and 'call' functions (load and run Lua code) | 267 | ** 'load' and 'call' functions (load and run Lua code) |
| 264 | */ | 268 | */ |
| 265 | LUA_API void (lua_callk) (lua_State *L, int nargs, int nresults, int ctx, | 269 | LUA_API void (lua_callk) (lua_State *L, int nargs, int nresults, lua_Ctx ctx, |
| 266 | lua_KFunction k); | 270 | lua_KFunction k); |
| 267 | #define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL) | 271 | #define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL) |
| 268 | 272 | ||
| 269 | LUA_API int (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc, | 273 | LUA_API int (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc, |
| 270 | int ctx, lua_KFunction k); | 274 | lua_Ctx ctx, lua_KFunction k); |
| 271 | #define lua_pcall(L,n,r,f) lua_pcallk(L, (n), (r), (f), 0, NULL) | 275 | #define lua_pcall(L,n,r,f) lua_pcallk(L, (n), (r), (f), 0, NULL) |
| 272 | 276 | ||
| 273 | LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt, | 277 | 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); | |||
| 280 | /* | 284 | /* |
| 281 | ** coroutine functions | 285 | ** coroutine functions |
| 282 | */ | 286 | */ |
| 283 | LUA_API int (lua_yieldk) (lua_State *L, int nresults, int ctx, | 287 | LUA_API int (lua_yieldk) (lua_State *L, int nresults, lua_Ctx ctx, |
| 284 | lua_KFunction k); | 288 | lua_KFunction k); |
| 285 | #define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL) | 289 | #define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL) |
| 286 | LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg); | 290 | LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: luaconf.h,v 1.208 2014/06/24 17:02:00 roberto Exp roberto $ | 2 | ** $Id: luaconf.h,v 1.209 2014/06/26 18:30:27 roberto Exp roberto $ |
| 3 | ** Configuration file for Lua | 3 | ** Configuration file for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -254,6 +254,22 @@ | |||
| 254 | #define LUAI_MAXSHORTLEN 40 | 254 | #define LUAI_MAXSHORTLEN 40 |
| 255 | 255 | ||
| 256 | 256 | ||
| 257 | /* | ||
| 258 | @@ LUA_CTXT is the type of the context ('ctx') for continuation functions. | ||
| 259 | @@ It must be a numerical type; Lua will use 'intptr_t' if available. | ||
| 260 | */ | ||
| 261 | #if defined (LUA_USE_C99) | ||
| 262 | #include <stdint.h> | ||
| 263 | #if defined (INTPTR_MAX) /* even in C99 this type is optional */ | ||
| 264 | #define LUA_CTXT intptr_t | ||
| 265 | #endif | ||
| 266 | #endif | ||
| 267 | |||
| 268 | #if !defined(LUA_CTXT) | ||
| 269 | /* default definition (the nearest thing to 'intptr_t' in C89) */ | ||
| 270 | #define LUA_CTXT ptrdiff_t | ||
| 271 | #endif | ||
| 272 | |||
| 257 | 273 | ||
| 258 | /* | 274 | /* |
| 259 | ** {================================================================== | 275 | ** {================================================================== |
