Tab-completion in REPL based on module variables.
This commit is contained in:
@@ -36,6 +36,34 @@ void metaCompile(WrenVM* vm)
|
||||
}
|
||||
}
|
||||
|
||||
void metaGetModuleVariables(WrenVM* vm) {
|
||||
wrenEnsureSlots(vm, 3);
|
||||
|
||||
Value moduleValue = wrenMapGet(vm->modules, vm->apiStack[1]);
|
||||
if (IS_UNDEFINED(moduleValue))
|
||||
{
|
||||
vm->apiStack[0] = NULL_VAL;
|
||||
return;
|
||||
}
|
||||
|
||||
ObjModule* module = AS_MODULE(moduleValue);
|
||||
ObjList* names = wrenNewList(vm, module->variableNames.count);
|
||||
vm->apiStack[0] = OBJ_VAL(names);
|
||||
|
||||
// Initialize the elements to null in case a collection happens when we
|
||||
// allocate the strings below.
|
||||
for (int i = 0; i < names->elements.count; i++)
|
||||
{
|
||||
names->elements.data[i] = NULL_VAL;
|
||||
}
|
||||
|
||||
for (int i = 0; i < names->elements.count; i++)
|
||||
{
|
||||
String* name = &module->variableNames.data[i];
|
||||
names->elements.data[i] = wrenNewString(vm, name->buffer, name->length);
|
||||
}
|
||||
}
|
||||
|
||||
const char* wrenMetaSource()
|
||||
{
|
||||
return metaModuleSource;
|
||||
@@ -49,9 +77,19 @@ WrenForeignMethodFn wrenMetaBindForeignMethod(WrenVM* vm,
|
||||
// There is only one foreign method in the meta module.
|
||||
ASSERT(strcmp(className, "Meta") == 0, "Should be in Meta class.");
|
||||
ASSERT(isStatic, "Should be static.");
|
||||
ASSERT(strcmp(signature, "compile_(_,_,_)") == 0, "Should be compile method.");
|
||||
|
||||
return metaCompile;
|
||||
if (strcmp(signature, "compile_(_,_,_)") == 0)
|
||||
{
|
||||
return metaCompile;
|
||||
}
|
||||
|
||||
if (strcmp(signature, "getModuleVariables_(_)") == 0)
|
||||
{
|
||||
return metaGetModuleVariables;
|
||||
}
|
||||
|
||||
ASSERT(false, "Unknown method.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
class Meta {
|
||||
static getModuleVariables(module) {
|
||||
if (!(module is String)) Fiber.abort("Module name must be a string.")
|
||||
var result = getModuleVariables_(module)
|
||||
if (result != null) return result
|
||||
|
||||
Fiber.abort("Could not find a module named '%(module)'.")
|
||||
}
|
||||
|
||||
static eval(source) {
|
||||
if (!(source is String)) Fiber.abort("Source code must be a string.")
|
||||
|
||||
@@ -15,4 +23,5 @@ class Meta {
|
||||
}
|
||||
|
||||
foreign static compile_(source, isExpression, printErrors)
|
||||
foreign static getModuleVariables_(module)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
// Generated automatically from src/optional/wren_opt_meta.wren. Do not edit.
|
||||
static const char* metaModuleSource =
|
||||
"class Meta {\n"
|
||||
" static getModuleVariables(module) {\n"
|
||||
" if (!(module is String)) Fiber.abort(\"Module name must be a string.\")\n"
|
||||
" var result = getModuleVariables_(module)\n"
|
||||
" if (result != null) return result\n"
|
||||
"\n"
|
||||
" Fiber.abort(\"Could not find a module named '%(module)'.\")\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" static eval(source) {\n"
|
||||
" if (!(source is String)) Fiber.abort(\"Source code must be a string.\")\n"
|
||||
"\n"
|
||||
@@ -17,4 +25,5 @@ static const char* metaModuleSource =
|
||||
" }\n"
|
||||
"\n"
|
||||
" foreign static compile_(source, isExpression, printErrors)\n"
|
||||
" foreign static getModuleVariables_(module)\n"
|
||||
"}\n";
|
||||
|
||||
Reference in New Issue
Block a user