Skip to content

Commit 50805be

Browse files
committed
Add information about value types.
1 parent 8ad5299 commit 50805be

File tree

3 files changed

+46
-8
lines changed

3 files changed

+46
-8
lines changed

source/cli/plugins/cli_core_plugin/source/cli_core_plugin.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ void *load(size_t argc, void *args[], void *data)
7575
}
7676
else
7777
{
78-
log_write("metacall", LOG_LEVEL_ERROR, "Calling load with wrong type of argument at argument position %" PRIuS ", expected metacall value id %" PRIuS " , got %" PRIuS,
79-
i + 1, METACALL_STRING, metacall_value_id(script_val[i]));
78+
log_write("metacall", LOG_LEVEL_ERROR, "Calling load with wrong type of argument at argument position %" PRIuS ", expected %s, got %s",
79+
i + 1, metacall_value_id_name(METACALL_STRING), metacall_value_type_name(script_val[i]));
8080
return metacall_value_create_int(1);
8181
}
8282
}
@@ -107,8 +107,8 @@ void *eval(size_t argc, void *args[], void *data)
107107
}
108108
else
109109
{
110-
log_write("metacall", LOG_LEVEL_ERROR, "Calling eval with wrong type of arguments, expected metacall value id %" PRIuS " , got %" PRIuS " and %" PRIuS,
111-
METACALL_STRING, metacall_value_id(args[0]), metacall_value_id(args[1]));
110+
log_write("metacall", LOG_LEVEL_ERROR, "Calling eval with wrong type of arguments, expected two %s, got %s and %s",
111+
metacall_value_id_name(METACALL_STRING), metacall_value_type_name(args[0]), metacall_value_type_name(args[1]));
112112
}
113113

114114
return metacall_value_create_int(1);
@@ -127,7 +127,8 @@ void *await(size_t argc, void *args[], void *data)
127127

128128
if (metacall_value_id(args[0]) != METACALL_STRING)
129129
{
130-
log_write("metacall", LOG_LEVEL_ERROR, "Calling await with wrong type of arguments, expected metacall value id %" PRIuS " , got %" PRIuS, METACALL_STRING, metacall_value_id(args[0]));
130+
log_write("metacall", LOG_LEVEL_ERROR, "Calling await with wrong type of arguments, expected %s, got %s",
131+
metacall_value_id_name(METACALL_STRING), metacall_value_type_name(args[0]));
131132
return metacall_value_create_int(1);
132133
}
133134

@@ -217,7 +218,8 @@ void *call(size_t argc, void *args[], void *data)
217218

218219
if (metacall_value_id(args[0]) != METACALL_STRING)
219220
{
220-
log_write("metacall", LOG_LEVEL_ERROR, "Calling call with wrong type of arguments, expected metacall value id %" PRIuS " , got %" PRIuS, METACALL_STRING, metacall_value_id(args[0]));
221+
log_write("metacall", LOG_LEVEL_ERROR, "Calling call with wrong type of arguments, expected %s, got %s",
222+
metacall_value_id_name(METACALL_STRING), metacall_value_type_name(args[0]));
221223
return metacall_value_create_int(1);
222224
}
223225

@@ -268,8 +270,8 @@ void *clear(size_t argc, void *args[], void *data)
268270

269271
if (metacall_value_id(args[0]) != METACALL_STRING && metacall_value_id(args[1]) != METACALL_STRING)
270272
{
271-
log_write("metacall", LOG_LEVEL_ERROR, "Calling clear with wrong type of arguments, expected metacall value id %" PRIuS " , got %" PRIuS " and %" PRIuS,
272-
METACALL_STRING, metacall_value_id(args[0]), metacall_value_id(args[1]));
273+
log_write("metacall", LOG_LEVEL_ERROR, "Calling clear with wrong type of arguments, expected two %s, got %s and %s",
274+
metacall_value_id_name(METACALL_STRING), metacall_value_type_name(args[0]), metacall_value_type_name(args[1]));
273275
return metacall_value_create_int(1);
274276
}
275277

source/metacall/include/metacall/metacall_value.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,30 @@ METACALL_API size_t metacall_value_count(void *v);
357357
*/
358358
METACALL_API enum metacall_value_id metacall_value_id(void *v);
359359

360+
/**
361+
* @brief
362+
* Provide type id in a readable form (as string) of a type id
363+
*
364+
* @param[in] id
365+
* Value type identifier
366+
*
367+
* @return
368+
* Return string related to the type id
369+
*/
370+
METACALL_API const char *metacall_value_id_name(enum metacall_value_id id);
371+
372+
/**
373+
* @brief
374+
* Provide type id in a readable form (as string) of value
375+
*
376+
* @param[in] v
377+
* Reference to the value
378+
*
379+
* @return
380+
* Return string related to the type id assigned to value
381+
*/
382+
METACALL_API const char *metacall_value_type_name(void *v);
383+
360384
/**
361385
* @brief
362386
* Deep copies the value @v, the result copy resets

source/metacall/source/metacall_value.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,18 @@ enum metacall_value_id metacall_value_id(void *v)
206206
return METACALL_INVALID;
207207
}
208208

209+
const char *metacall_value_id_name(enum metacall_value_id id)
210+
{
211+
return type_id_name(id);
212+
}
213+
214+
const char *metacall_value_type_name(void *v)
215+
{
216+
type_id id = value_type_id(v);
217+
218+
return type_id_name(id);
219+
}
220+
209221
void *metacall_value_copy(void *v)
210222
{
211223
return value_type_copy(v);

0 commit comments

Comments
 (0)