Make embedding API provide full method signature.

This commit is contained in:
Bob Nystrom
2015-02-26 07:44:45 -08:00
parent 22edfd7e7f
commit e007bb7f11
3 changed files with 22 additions and 33 deletions
+4 -4
View File
@@ -140,10 +140,10 @@ static void ioTime(WrenVM* vm)
void wrenLoadIOLibrary(WrenVM* vm)
{
wrenInterpret(vm, "", libSource);
wrenDefineStaticMethod(vm, "IO", "writeString_", 1, ioWriteString);
wrenDefineStaticMethod(vm, "IO", "clock", 0, ioClock);
wrenDefineStaticMethod(vm, "IO", "time", 0, ioTime);
wrenDefineStaticMethod(vm, "IO", "read", 0, ioRead);
wrenDefineStaticMethod(vm, "IO", "writeString_ ", ioWriteString);
wrenDefineStaticMethod(vm, "IO", "clock", ioClock);
wrenDefineStaticMethod(vm, "IO", "time", ioTime);
wrenDefineStaticMethod(vm, "IO", "read", ioRead);
}
#endif
+10 -21
View File
@@ -1339,17 +1339,14 @@ void wrenPopRoot(WrenVM* vm)
}
static void defineMethod(WrenVM* vm, const char* className,
const char* methodName, int numParams,
const char* signature,
WrenForeignMethodFn methodFn, bool isStatic)
{
ASSERT(className != NULL, "Must provide class name.");
int length = (int)strlen(methodName);
ASSERT(methodName != NULL, "Must provide method name.");
ASSERT(strlen(methodName) < MAX_METHOD_NAME, "Method name too long.");
ASSERT(numParams >= 0, "numParams cannot be negative.");
ASSERT(numParams <= MAX_PARAMETERS, "Too many parameters.");
int length = (int)strlen(signature);
ASSERT(signature != NULL, "Must provide signature.");
ASSERT(strlen(signature) < MAX_METHOD_SIGNATURE, "Signature too long.");
ASSERT(methodFn != NULL, "Must provide method function.");
@@ -1382,17 +1379,9 @@ static void defineMethod(WrenVM* vm, const char* className,
wrenPopRoot(vm);
}
// Create a name for the method, including its arity.
char name[MAX_METHOD_SIGNATURE];
memcpy(name, methodName, length);
for (int i = 0; i < numParams; i++)
{
name[length++] = ' ';
}
name[length] = '\0';
// Bind the method.
int methodSymbol = wrenSymbolTableEnsure(vm, &vm->methodNames, name, length);
int methodSymbol = wrenSymbolTableEnsure(vm, &vm->methodNames,
signature, length);
Method method;
method.type = METHOD_FOREIGN;
@@ -1404,17 +1393,17 @@ static void defineMethod(WrenVM* vm, const char* className,
}
void wrenDefineMethod(WrenVM* vm, const char* className,
const char* methodName, int numParams,
const char* signature,
WrenForeignMethodFn methodFn)
{
defineMethod(vm, className, methodName, numParams, methodFn, false);
defineMethod(vm, className, signature, methodFn, false);
}
void wrenDefineStaticMethod(WrenVM* vm, const char* className,
const char* methodName, int numParams,
const char* signature,
WrenForeignMethodFn methodFn)
{
defineMethod(vm, className, methodName, numParams, methodFn, true);
defineMethod(vm, className, signature, methodFn, true);
}
bool wrenGetArgumentBool(WrenVM* vm, int index)