diff options
-rw-r--r-- | src/scripting/bindings/viewport.c | 6 | ||||
-rw-r--r-- | src/scripting/ffi.c | 45 | ||||
-rw-r--r-- | src/scripting/ffi.h | 12 |
3 files changed, 37 insertions, 26 deletions
diff --git a/src/scripting/bindings/viewport.c b/src/scripting/bindings/viewport.c index 2f3c03d..8fcc041 100644 --- a/src/scripting/bindings/viewport.c +++ b/src/scripting/bindings/viewport.c @@ -24,13 +24,13 @@ static struct ffi_namespace *ns; static void -binding_set_size(void) +binding_set_size(struct ffi_function *fn) { Uint16 width; Uint16 height; - width = ffi_stack_get_int(); - height = ffi_stack_get_int(); + width = ffi_stack_get_int(fn); + height = ffi_stack_get_int(fn); init_viewport(width, height, 8); } 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); diff --git a/src/scripting/ffi.h b/src/scripting/ffi.h index 471cd16..5b9de71 100644 --- a/src/scripting/ffi.h +++ b/src/scripting/ffi.h @@ -23,7 +23,7 @@ struct ffi_function { const char *name; - void (*func)(void); + void (*func)(struct ffi_function *); struct ffi_function *next; }; struct ffi_namespace { @@ -38,13 +38,13 @@ struct ffi_namespace { struct ffi_namespace *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 *)); void ffi_register_functions(struct script *script); void ffi_context_switch(struct script *script); -int ffi_stack_get_bool(void); -int ffi_stack_get_int(void); -double ffi_stack_get_float(void); -const char *ffi_stack_get_string(void); +int ffi_stack_get_bool(struct ffi_function *fn); +int ffi_stack_get_int(struct ffi_function *fn); +double ffi_stack_get_float(struct ffi_function *fn); +const char *ffi_stack_get_string(struct ffi_function *fn); void ffi_prepare_call(const char *func); void ffi_stack_set_bool(int v); void ffi_stack_set_int(int v); |