+ inputBuffer = *history_position;
+ inputBufferPosition = inputBuffer.length();
+ }
+}
+
+void
+Console::move_cursor(int offset)
+{
+ if (offset == -65535) inputBufferPosition = 0;
+ if (offset == +65535) inputBufferPosition = inputBuffer.length();
+ inputBufferPosition+=offset;
+ if (inputBufferPosition < 0) inputBufferPosition = 0;
+ if (inputBufferPosition > (int)inputBuffer.length()) inputBufferPosition = inputBuffer.length();
+}
+
+// Helper functions for Console::autocomplete
+// TODO: Fix rough documentation
+namespace {
+
+void sq_insert_commands(std::list<std::string>& cmds, HSQUIRRELVM vm, std::string table_prefix, std::string search_prefix);
+
+/**
+ * Acts upon key,value on top of stack:
+ * Appends key (plus type-dependent suffix) to cmds if table_prefix+key starts with search_prefix;
+ * Calls sq_insert_commands if search_prefix starts with table_prefix+key (and value is a table/class/instance);
+ */
+void
+sq_insert_command(std::list<std::string>& cmds, HSQUIRRELVM vm, std::string table_prefix, std::string search_prefix)
+{
+ const SQChar* key_chars;
+ if (SQ_FAILED(sq_getstring(vm, -2, &key_chars))) return;
+ std::string key_string = table_prefix + key_chars;
+
+ switch (sq_gettype(vm, -1)) {
+ case OT_INSTANCE:
+ key_string+=".";
+ if (search_prefix.substr(0, key_string.length()) == key_string) {
+ sq_getclass(vm, -1);
+ sq_insert_commands(cmds, vm, key_string, search_prefix);
+ sq_pop(vm, 1);
+ }
+ break;
+ case OT_TABLE:
+ case OT_CLASS:
+ key_string+=".";
+ if (search_prefix.substr(0, key_string.length()) == key_string) {
+ sq_insert_commands(cmds, vm, key_string, search_prefix);
+ }
+ break;
+ case OT_CLOSURE:
+ case OT_NATIVECLOSURE:
+ key_string+="()";
+ break;
+ default:
+ break;