Using other languages with the ace in-line filter

Using other languages with the ace in-line filter

von Richard Lobb -
Anzahl Antworten: 0

A user emailed me the following question:

 

I created a new CodeRunner question prototype called mycpp_program in a Moodle course, because I needed additional compiler flags for C++ code. The prototype appears correctly in the list of question types when adding a new CodeRunner question, and it works inside quizzes.

However, when I try to use this custom prototype inside an ace_inline filter code block like this:

<pre class="language-c" data-language="mycpp_program" data-ace-interactive-code>
<code>
int main() {
}
</code>
</pre>
 

Clicking “Try it!” gives the error:

*** Run Error ***
qtype_coderunner/Language "mycpp_program" is not known
 

1) How can I make a custom CodeRunner prototype such as mycpp_program available to the ACE inline filter so that it can be used for “Try it!” execution on Moodle course pages?

In other words, how to add a new language so that it will appear in the quiz as well as ACE inline filter of the course page?

2) Even though it is discouraged to edit the file builtin_PROTOTYPES.xml to add a new language, I want to know the proper method of doing it. (Because, even after adding a new language in builtin_PROTOTYPES.xml, the upgrade process is not adding the new language in the displayed list) 

 

Anyway, I have to thank you all for providing the Coderunner plugin. In addition to that, I have to thank you for providing the Ace inline filter; which is excellent and unique. (VPL misses this functionality)

Response

The Ace In-line Filter (AILF) is designed to be like a short-cut from the student's browser to the Jobe server, which is the sandbox machine that runs all CodeRunner submissions. The AILF allows students to test code directly from within their browser, as if they had an IDE available. In principle AILF requests bypass Moodle altogether though in practice they needs to go via Moodle for authentication and, if enabled, logging of each request.

As with an IDE, Moodle specifics, such as tests, boiler-plate code or other customised question properties, are not directly available through the AILF. Creating a new question type in Moodle doesn't create a new question type on Jobe, so the AILF won't recognise it as a new language. Only languages provided directly by Jobe can be specified as the value of the data-lang parameter.

However, you can usually customise the AILF box to behave like a customised question.

In your case, it sounds like you're simply changing the sandbox parameters to give you different compile options. That's easily achieved with an AILF box by use of the data-params attribute, which serves the same role as the sandbox parameters field in the Moodle question authoring panel. It just passes parameters - "run-spec parameters" in Jobe parlance - directly through to Jobe.

So in your case if you just want to change the compiler options, you can specify the compileargs run-spec parameter with an AILF box that begins something like this (which sets the language standard to c++11):

<pre class="ace-interactive-code" data-lang="cpp"
  data-params="{&quot;compileargs&quot;:[&quot;-std=c++11&quot;]}">

The syntax is fiddly. The parameter you wish to pass to Jobe is

{"compileargs":["-std=c++11"]}

The easiest way to set that when editing the opening <pre> element for the AILF box is to use single quotes for the value of the data-params attribute. The Tiny MCE editor will convert those to double quotes and convert the internal double quotes to HTML entities. That is, you type

data-params='{"compileargs":["-std=c++11"]}'

and that gets converted to the version you see above.