summaryrefslogtreecommitdiffstats
path: root/src/scripting
diff options
context:
space:
mode:
Diffstat (limited to 'src/scripting')
-rw-r--r--src/scripting/ffi.c62
-rw-r--r--src/scripting/ffi.h2
2 files changed, 42 insertions, 22 deletions
diff --git a/src/scripting/ffi.c b/src/scripting/ffi.c
index 0d43f86..6a30a94 100644
--- a/src/scripting/ffi.c
+++ b/src/scripting/ffi.c
@@ -16,6 +16,7 @@
* <http://www.gnu.org/licenses/>.
*/
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <lua.h>
@@ -36,6 +37,7 @@ static struct ffi_namespace root = {
NULL,
NULL,
NULL,
+ NULL,
};
static int call_arg_index;
@@ -58,6 +60,21 @@ ffi_add_namespace(struct ffi_namespace *parent, const char *name)
return NULL;
}
new_ns->name = strdup(name);
+ new_ns->full_name = calloc(
+ (parent->full_name != NULL ? strlen(parent->full_name)
+ + 1 : 0)
+ + strlen(name)
+ + 1,
+ sizeof(*new_ns->full_name));
+ if (new_ns->full_name == NULL) {
+ free(new_ns);
+ err(1, "Failed to allocate FFI namespace \"%s\"", name);
+ return NULL;
+ }
+ sprintf(new_ns->full_name, "%s%s%s",
+ (parent->full_name != NULL ? parent->full_name : ""),
+ (parent->full_name != NULL ? ":" : ""),
+ name);
new_ns->ns_head = NULL;
new_ns->ns_tail = NULL;
new_ns->fn_head = NULL;
@@ -86,6 +103,7 @@ ffi_add_function(struct ffi_namespace *parent, const char *name,
return;
}
new_fn->name = strdup(name);
+ new_fn->ns = parent;
new_fn->func = func;
new_fn->next = NULL;
@@ -146,13 +164,13 @@ int
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)",
- call_arg_index, fn->name);
+ warn("Bad argument #%d to %s:%s() (no value)",
+ call_arg_index, fn->ns->full_name, fn->name);
return 0;
}
if (!lua_isboolean(ctx->lua_state, call_arg_index)) {
- warn("Bad argument #%d to %s (boolean expected)",
- call_arg_index, fn->name);
+ warn("Bad argument #%d to %s:%s() (boolean expected)",
+ call_arg_index, fn->ns->full_name, fn->name);
return 0;
}
return lua_toboolean(ctx->lua_state, call_arg_index);
@@ -163,8 +181,8 @@ 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)",
- call_arg_index, fn->name);
+ warn("Bad argument #%d to %s:%s() (no value)",
+ call_arg_index, fn->ns->full_name, fn->name);
return 0;
}
return lua_tointeger(ctx->lua_state, call_arg_index);
@@ -173,26 +191,26 @@ ffi_stack_get_int(struct ffi_function *fn)
int is_int;
if (lua_gettop(ctx->lua_state) < ++call_arg_index) {
- warn("Bad argument #%d to %s (no value)",
- call_arg_index, fn->name);
+ warn("Bad argument #%d to %s:%s() (no value)",
+ call_arg_index, fn->ns->full_name, 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)",
- call_arg_index, fn->name);
+ warn("Bad argument #%d to %s:%s() (integer expected)",
+ call_arg_index, fn->ns->full_name, 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)",
- call_arg_index, fn->name);
+ warn("Bad argument #%d to %s:%s() (no value)",
+ call_arg_index, fn->ns->full_name, fn->name);
return 0;
}
if (!lua_isinteger(ctx->lua_state, call_arg_index)) {
- warn("Bad argument #%d to %s (integer expected)",
- call_arg_index, fn->name);
+ warn("Bad argument #%d to %s:%s() (integer expected)",
+ call_arg_index, fn->ns->full_name, fn->name);
return 0;
}
return lua_tointeger(ctx->lua_state, call_arg_index);
@@ -203,13 +221,13 @@ double
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)",
- call_arg_index, fn->name);
+ warn("Bad argument #%d to %s:%s() (no value)",
+ call_arg_index, fn->ns->full_name, fn->name);
return 0;
}
if (!lua_isnumber(ctx->lua_state, call_arg_index)) {
- warn("Bad argument #%d to %s (number expected)",
- call_arg_index, fn->name);
+ warn("Bad argument #%d to %s:%s() (number expected)",
+ call_arg_index, fn->ns->full_name, fn->name);
return 0;
}
return lua_tonumber(ctx->lua_state, call_arg_index);
@@ -219,13 +237,13 @@ const char *
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)",
- call_arg_index, fn->name);
+ warn("Bad argument #%d to %s:%s() (no value)",
+ call_arg_index, fn->ns->full_name, fn->name);
return 0;
}
if (!lua_isstring(ctx->lua_state, call_arg_index)) {
- warn("Bad argument #%d to %s (string expected)",
- call_arg_index, fn->name);
+ warn("Bad argument #%d to %s:%s() (string expected)",
+ call_arg_index, fn->ns->full_name, 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 5b9de71..fa3eb56 100644
--- a/src/scripting/ffi.h
+++ b/src/scripting/ffi.h
@@ -23,11 +23,13 @@
struct ffi_function {
const char *name;
+ struct ffi_namespace *ns;
void (*func)(struct ffi_function *);
struct ffi_function *next;
};
struct ffi_namespace {
const char *name;
+ char *full_name;
struct ffi_namespace *ns_head;
struct ffi_namespace *ns_tail;
struct ffi_function *fn_head;