diff options
Diffstat (limited to 'src/scripting/ffi.c')
-rw-r--r-- | src/scripting/ffi.c | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/src/scripting/ffi.c b/src/scripting/ffi.c index 785db37..0d43f86 100644 --- a/src/scripting/ffi.c +++ b/src/scripting/ffi.c @@ -76,7 +76,7 @@ ffi_add_namespace(struct ffi_namespace *parent, const char *name) void ffi_add_function(struct ffi_namespace *parent, const char *name, - void (*func)(void)) + void (*func)(struct ffi_function *)) { struct ffi_function *new_fn; @@ -132,7 +132,7 @@ ffi_handle_function(lua_State *l) struct ffi_function *fn; fn = (struct ffi_function *) lua_touserdata(l, lua_upvalueindex(1)); - fn->func(); + fn->func(fn); return 0; } @@ -143,25 +143,28 @@ void ffi_context_switch(struct script *script) } int -ffi_stack_get_bool(void) +ffi_stack_get_bool(struct ffi_function *fn) { if (lua_gettop(ctx->lua_state) < ++call_arg_index) { - warn("Bad argument #%d to %s (no value)"); + warn("Bad argument #%d to %s (no value)", + call_arg_index, fn->name); return 0; } if (!lua_isboolean(ctx->lua_state, call_arg_index)) { - warn("Bad argument #%d to %s (boolean expected)"); + warn("Bad argument #%d to %s (boolean expected)", + call_arg_index, fn->name); return 0; } return lua_toboolean(ctx->lua_state, call_arg_index); } int -ffi_stack_get_int(void) +ffi_stack_get_int(struct ffi_function *fn) { #if LUA_VERSION_NUM <= 501 if (lua_gettop(ctx->lua_state) < ++call_arg_index) { - warn("Bad argument #%d to %s (no value)"); + warn("Bad argument #%d to %s (no value)", + call_arg_index, fn->name); return 0; } return lua_tointeger(ctx->lua_state, call_arg_index); @@ -170,22 +173,26 @@ ffi_stack_get_int(void) int is_int; if (lua_gettop(ctx->lua_state) < ++call_arg_index) { - warn("Bad argument #%d to %s (no value)"); + warn("Bad argument #%d to %s (no value)", + call_arg_index, fn->name); return 0; } v = lua_tointegerx(ctx->lua_state, call_arg_index, &is_int); if (!is_int) { - warn("Bad argument #%d to %s (integer expected)"); + warn("Bad argument #%d to %s (integer expected)", + call_arg_index, fn->name); return 0; } return v; #elif LUA_VERSION_NUM >= 503 if (lua_gettop(ctx->lua_state) < ++call_arg_index) { - warn("Bad argument #%d to %s (no value)"); + warn("Bad argument #%d to %s (no value)", + call_arg_index, fn->name); return 0; } if (!lua_isinteger(ctx->lua_state, call_arg_index)) { - warn("Bad argument #%d to %s (integer expected)"); + warn("Bad argument #%d to %s (integer expected)", + call_arg_index, fn->name); return 0; } return lua_tointeger(ctx->lua_state, call_arg_index); @@ -193,28 +200,32 @@ ffi_stack_get_int(void) } double -ffi_stack_get_float(void) +ffi_stack_get_float(struct ffi_function *fn) { if (lua_gettop(ctx->lua_state) < ++call_arg_index) { - warn("Bad argument #%d to %s (no value)"); + warn("Bad argument #%d to %s (no value)", + call_arg_index, fn->name); return 0; } if (!lua_isnumber(ctx->lua_state, call_arg_index)) { - warn("Bad argument #%d to %s (number expected)"); + warn("Bad argument #%d to %s (number expected)", + call_arg_index, fn->name); return 0; } return lua_tonumber(ctx->lua_state, call_arg_index); } const char * -ffi_stack_get_string(void) +ffi_stack_get_string(struct ffi_function *fn) { if (lua_gettop(ctx->lua_state) < ++call_arg_index) { - warn("Bad argument #%d to %s (no value)"); + warn("Bad argument #%d to %s (no value)", + call_arg_index, fn->name); return 0; } if (!lua_isstring(ctx->lua_state, call_arg_index)) { - warn("Bad argument #%d to %s (string expected)"); + warn("Bad argument #%d to %s (string expected)", + call_arg_index, fn->name); return 0; } return lua_tostring(ctx->lua_state, call_arg_index); |