diff options
author | Mike Pall <mike> | 2010-02-13 04:51:56 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2010-02-13 04:51:56 +0100 |
commit | c93138b59e8f28b3d412cd7ec0c6631fd27e3e1b (patch) | |
tree | 8c0ffe2086ab0b032ed8e9f92ae6fb9d4d040d66 /doc | |
parent | 4f8d7be8ea8a103f4d9046188d6005740b74f3d4 (diff) | |
download | luajit-c93138b59e8f28b3d412cd7ec0c6631fd27e3e1b.tar.gz luajit-c93138b59e8f28b3d412cd7ec0c6631fd27e3e1b.tar.bz2 luajit-c93138b59e8f28b3d412cd7ec0c6631fd27e3e1b.zip |
Major redesign of function call handling.
Drop call gates. Use function headers, dispatched like bytecodes.
Emit BC_FUNCF/BC_FUNCV bytecode at PC 0 for all Lua functions.
C functions and ASM fast functions get extra bytecodes.
Modify internal calling convention: new base in BASE (formerly in RA).
Can now use better C function wrapper semantics (dynamic on/off).
Prerequisite for call hooks with zero-overhead if disabled.
Prerequisite for compiling recursive calls.
Prerequisite for efficient 32/64 bit prototype guards.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/api.html | 38 |
1 files changed, 13 insertions, 25 deletions
diff --git a/doc/api.html b/doc/api.html index af438ad2..f20e5e21 100644 --- a/doc/api.html +++ b/doc/api.html | |||
@@ -258,13 +258,12 @@ side traces from the cache. | |||
258 | 258 | ||
259 | <h3 id="mode_engine"><tt>luaJIT_setmode(L, idx, LUAJIT_MODE_WRAPCFUNC|flag)</tt></h3> | 259 | <h3 id="mode_engine"><tt>luaJIT_setmode(L, idx, LUAJIT_MODE_WRAPCFUNC|flag)</tt></h3> |
260 | <p> | 260 | <p> |
261 | This mode defines a wrapper function for calls to C functions. The | 261 | This mode defines a wrapper function for calls to C functions. If |
262 | first time this is called with <tt>LUAJIT_MODE_ON</tt>, the stack | 262 | called with <tt>LUAJIT_MODE_ON</tt>, the stack index at <tt>idx</tt> |
263 | index at <tt>idx</tt> must be a <tt>lightuserdata</tt> object holding | 263 | must be a <tt>lightuserdata</tt> object holding a pointer to the wrapper |
264 | a pointer to the wrapper function. All <b>subsequently created C | 264 | function. From now on all C functions are called through the wrapper |
265 | functions</b> are called through the wrapper functions. After the initial | 265 | function. If called with <tt>LUAJIT_MODE_OFF</tt> this mode is turned |
266 | definition <tt>idx</tt> can be left at <tt>0</tt> when turning the mode | 266 | off and all C functions are directly called. |
267 | on or off. | ||
268 | </p> | 267 | </p> |
269 | <p> | 268 | <p> |
270 | The wrapper function can be used for debugging purposes or to catch | 269 | The wrapper function can be used for debugging purposes or to catch |
@@ -291,38 +290,27 @@ static int wrap_exceptions(lua_State *L, lua_CFunction f) | |||
291 | return lua_error(L); // Rethrow as a Lua error. | 290 | return lua_error(L); // Rethrow as a Lua error. |
292 | } | 291 | } |
293 | 292 | ||
294 | static int myregister(lua_State *L) | 293 | static int myinit(lua_State *L) |
295 | { | 294 | { |
296 | ... | 295 | ... |
297 | // Define wrapper function and enable it. | 296 | // Define wrapper function and enable it. |
298 | lua_pushlightuserdata(L, (void *)wrap_exceptions); | 297 | lua_pushlightuserdata(L, (void *)wrap_exceptions); |
299 | luaJIT_setmode(L, -1, LUAJIT_MODE_WRAPCFUNC|LUAJIT_MODE_ON); | 298 | luaJIT_setmode(L, -1, LUAJIT_MODE_WRAPCFUNC|LUAJIT_MODE_ON); |
300 | lua_pop(L, 1); | 299 | lua_pop(L, 1); |
301 | luaL_register(L, "mymodule", myfuncs); // Pass luaL_Reg list. | ||
302 | luaJIT_setmode(L, 0, LUAJIT_MODE_WRAPCFUNC|LUAJIT_MODE_OFF); | ||
303 | ... | ||
304 | // Wrap some more C++ functions which might throw an exception. | ||
305 | luaJIT_setmode(L, 0, LUAJIT_MODE_WRAPCFUNC|LUAJIT_MODE_ON); | ||
306 | lua_pushcfunction(L, mythrowingfunc1); | ||
307 | lua_pushcclosure(L, mythrowingfunc2, 1); | ||
308 | luaJIT_setmode(L, 0, LUAJIT_MODE_WRAPCFUNC|LUAJIT_MODE_OFF); | ||
309 | ... | 300 | ... |
310 | } | 301 | } |
311 | </pre> | 302 | </pre> |
312 | <p> | 303 | <p> |
313 | Note that you can only define <b>a single global wrapper function</b>, | 304 | Note that you can only define <b>a single global wrapper function</b>, |
314 | so be careful when using this mechanism from multiple C++ modules. | 305 | so be careful when using this mechanism from multiple C++ modules. |
315 | Also note that this mechanism is not without overhead. It should only | 306 | Also note that this mechanism is not without overhead. |
316 | be enabled for definitions of C++ functions that can actually throw | ||
317 | exceptions. If you're embedding LuaJIT into an application, only | ||
318 | enable it <b>after</b> running <tt>luaL_openlibs</tt>. | ||
319 | </p> | 307 | </p> |
320 | <p> | 308 | <p> |
321 | LuaJIT already intercepts exception handling for all x64 systems and | 309 | LuaJIT already intercepts exception handling for systems using DWARF2 |
322 | for x86 systems using DWARF2 stack unwinding (e.g. Linux, OSX). This | 310 | stack unwinding (e.g. Linux or OSX) and for Windows/x64 (but <b>not</b> |
323 | is a zero-cost mechanism and always enabled. You don't need to use any | 311 | for Windows/x86). This is a zero-cost mechanism and always enabled. |
324 | wrapper functions, except when you want to get a more specific error | 312 | You don't need to use any wrapper functions, except when you want to get |
325 | message than <tt>"C++ exception"</tt>. | 313 | a more specific error message than <tt>"C++ exception"</tt>. |
326 | </p> | 314 | </p> |
327 | <br class="flush"> | 315 | <br class="flush"> |
328 | </div> | 316 | </div> |