aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorMike Pall <mike>2010-02-13 04:51:56 +0100
committerMike Pall <mike>2010-02-13 04:51:56 +0100
commitc93138b59e8f28b3d412cd7ec0c6631fd27e3e1b (patch)
tree8c0ffe2086ab0b032ed8e9f92ae6fb9d4d040d66 /doc
parent4f8d7be8ea8a103f4d9046188d6005740b74f3d4 (diff)
downloadluajit-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.html38
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>
261This mode defines a wrapper function for calls to C functions. The 261This mode defines a wrapper function for calls to C functions. If
262first time this is called with <tt>LUAJIT_MODE_ON</tt>, the stack 262called with <tt>LUAJIT_MODE_ON</tt>, the stack index at <tt>idx</tt>
263index at <tt>idx</tt> must be a <tt>lightuserdata</tt> object holding 263must be a <tt>lightuserdata</tt> object holding a pointer to the wrapper
264a pointer to the wrapper function. All <b>subsequently created C 264function. From now on all C functions are called through the wrapper
265functions</b> are called through the wrapper functions. After the initial 265function. If called with <tt>LUAJIT_MODE_OFF</tt> this mode is turned
266definition <tt>idx</tt> can be left at <tt>0</tt> when turning the mode 266off and all C functions are directly called.
267on or off.
268</p> 267</p>
269<p> 268<p>
270The wrapper function can be used for debugging purposes or to catch 269The 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
294static int myregister(lua_State *L) 293static 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>
313Note that you can only define <b>a single global wrapper function</b>, 304Note that you can only define <b>a single global wrapper function</b>,
314so be careful when using this mechanism from multiple C++ modules. 305so be careful when using this mechanism from multiple C++ modules.
315Also note that this mechanism is not without overhead. It should only 306Also note that this mechanism is not without overhead.
316be enabled for definitions of C++ functions that can actually throw
317exceptions. If you're embedding LuaJIT into an application, only
318enable it <b>after</b> running <tt>luaL_openlibs</tt>.
319</p> 307</p>
320<p> 308<p>
321LuaJIT already intercepts exception handling for all x64 systems and 309LuaJIT already intercepts exception handling for systems using DWARF2
322for x86 systems using DWARF2 stack unwinding (e.g. Linux, OSX). This 310stack unwinding (e.g. Linux or OSX) and for Windows/x64 (but <b>not</b>
323is a zero-cost mechanism and always enabled. You don't need to use any 311for Windows/x86). This is a zero-cost mechanism and always enabled.
324wrapper functions, except when you want to get a more specific error 312You don't need to use any wrapper functions, except when you want to get
325message than <tt>"C++&nbsp;exception"</tt>. 313a more specific error message than <tt>"C++&nbsp;exception"</tt>.
326</p> 314</p>
327<br class="flush"> 315<br class="flush">
328</div> 316</div>