aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Janda <siffiejoe@gmx.net>2015-01-23 00:13:16 +0100
committerPhilipp Janda <siffiejoe@gmx.net>2015-01-23 00:13:16 +0100
commite084e2ca33537d378ca008fd13bb7d989f7d22d9 (patch)
treec96453bf6aeec108b0ee3bd5084bc43903cc1bbe
parenta2f72ce618a120c4299641c7fa2038caff890b30 (diff)
downloadlua-compat-5.3-e084e2ca33537d378ca008fd13bb7d989f7d22d9.tar.gz
lua-compat-5.3-e084e2ca33537d378ca008fd13bb7d989f7d22d9.tar.bz2
lua-compat-5.3-e084e2ca33537d378ca008fd13bb7d989f7d22d9.zip
document LUA_KFUNCTION macro, update readme
-rw-r--r--README.md39
1 files changed, 38 insertions, 1 deletions
diff --git a/README.md b/README.md
index 9a01583..303758e 100644
--- a/README.md
+++ b/README.md
@@ -142,6 +142,8 @@ For Lua 5.1 additionally:
142 142
143* bit operators 143* bit operators
144* integer division operator 144* integer division operator
145* utf8 escape sequences
146* 64 bit integers
145* `coroutine.isyieldable` 147* `coroutine.isyieldable`
146* Lua 5.1: `_ENV`, `goto`, labels, ephemeron tables, etc. See 148* Lua 5.1: `_ENV`, `goto`, labels, ephemeron tables, etc. See
147 [`lua-compat-5.2`][2] for a detailed list. 149 [`lua-compat-5.2`][2] for a detailed list.
@@ -149,7 +151,7 @@ For Lua 5.1 additionally:
149 * `lua_isyieldable` 151 * `lua_isyieldable`
150 * `lua_getextraspace` 152 * `lua_getextraspace`
151 * `lua_arith` (new operators missing) 153 * `lua_arith` (new operators missing)
152 * `lua_pushfstring` (new formats missing) 154 * `lua_push(v)fstring` (new formats missing)
153 * `lua_upvalueid` (5.1) 155 * `lua_upvalueid` (5.1)
154 * `lua_upvaluejoin` (5.1) 156 * `lua_upvaluejoin` (5.1)
155 * `lua_version` (5.1) 157 * `lua_version` (5.1)
@@ -158,6 +160,41 @@ For Lua 5.1 additionally:
158 * `luaL_loadbufferx` (5.1) 160 * `luaL_loadbufferx` (5.1)
159 * `luaL_loadfilex` (5.1) 161 * `luaL_loadfilex` (5.1)
160 162
163### Yieldable C functions
164
165The emulation of `lua_(p)callk` for previous Lua versions is not 100%
166perfect, because the continuation functions in Lua 5.2 have different
167signatures than the ones in Lua 5.3 (and Lua 5.1 doesn't have
168continuation functions at all). But with the help of a small macro the
169same code can be used for all three Lua versions (the 5.1 version
170won't support yielding though).
171
172Original Lua 5.3 code (example adapted from the Lua 5.3 manual):
173
174```C
175static int k (lua_State *L, int status, lua_KContext ctx) {
176 ... /* code 2 */
177}
178
179int original_function (lua_State *L) {
180 ... /* code 1 */
181 return k(L, lua_pcallk(L, n, m, h, ctx2, k), ctx1);
182}
183```
184
185Portable version:
186
187```C
188LUA_KFUNCTION( k ) {
189 ... /* code 2; parameters L, status, and ctx available here */
190}
191
192int original_function (lua_State *L) {
193 ... /* code 1 */
194 return k(L, lua_pcallk(L, n, m, h, ctx2, k), ctx1);
195}
196```
197
161## See also 198## See also
162 199
163* For Lua-5.2-style APIs under Lua 5.1, see [lua-compat-5.2][2], 200* For Lua-5.2-style APIs under Lua 5.1, see [lua-compat-5.2][2],