MIPS: Fix calls to floor/ceil/trunc.
[luajit-2.0/celess22.git] / src / lj_vmevent.c
blob5a74a5b02ab2b8a48b37341f751999016a1f9cb8
1 /*
2 ** VM event handling.
3 ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h
4 */
6 #include <stdio.h>
8 #define lj_vmevent_c
9 #define LUA_CORE
11 #include "lj_obj.h"
12 #include "lj_str.h"
13 #include "lj_tab.h"
14 #include "lj_state.h"
15 #include "lj_dispatch.h"
16 #include "lj_vm.h"
17 #include "lj_vmevent.h"
19 ptrdiff_t lj_vmevent_prepare(lua_State *L, VMEvent ev)
21 global_State *g = G(L);
22 GCstr *s = lj_str_newlit(L, LJ_VMEVENTS_REGKEY);
23 cTValue *tv = lj_tab_getstr(tabV(registry(L)), s);
24 if (tvistab(tv)) {
25 int hash = VMEVENT_HASH(ev);
26 tv = lj_tab_getint(tabV(tv), hash);
27 if (tv && tvisfunc(tv)) {
28 lj_state_checkstack(L, LUA_MINSTACK);
29 setfuncV(L, L->top++, funcV(tv));
30 return savestack(L, L->top);
33 g->vmevmask &= ~VMEVENT_MASK(ev); /* No handler: cache this fact. */
34 return 0;
37 void lj_vmevent_call(lua_State *L, ptrdiff_t argbase)
39 global_State *g = G(L);
40 uint8_t oldmask = g->vmevmask;
41 uint8_t oldh = hook_save(g);
42 int status;
43 g->vmevmask = 0; /* Disable all events. */
44 hook_vmevent(g);
45 status = lj_vm_pcall(L, restorestack(L, argbase), 0+1, 0);
46 if (LJ_UNLIKELY(status)) {
47 /* Really shouldn't use stderr here, but where else to complain? */
48 L->top--;
49 fprintf(stderr, "VM handler failed: %s\n",
50 tvisstr(L->top) ? strVdata(L->top) : "?");
52 hook_restore(g, oldh);
53 if (g->vmevmask != VMEVENT_NOCACHE)
54 g->vmevmask = oldmask; /* Restore event mask, but not if not modified. */