https://de.wikipedia.org/w/index.php?action=history&feed=atom&title=Modul%3ACompilerExplorerLink Modul:CompilerExplorerLink - Versionsgeschichte 2025-06-07T15:58:39Z Versionsgeschichte dieser Seite in Wikipedia MediaWiki 1.45.0-wmf.4 https://de.wikipedia.org/w/index.php?title=Modul:CompilerExplorerLink&diff=228612952&oldid=prev Ma.Brauer: Dieses Modul erzeugt aus einem Array von C-Quellcodes und Dateinamen einen Link zum Compiler Explorer, wo das entsprechende Programm compliiert und ausgeführt wird. 2022-12-06T09:30:22Z <p>Dieses Modul erzeugt aus einem Array von C-Quellcodes und Dateinamen einen Link zum Compiler Explorer, wo das entsprechende Programm compliiert und ausgeführt wird.</p> <p><b>Neue Seite</b></p><div>local CompilerExplorerLink = {}<br /> <br /> -- Konvertiert Dezimal-Integer in Hexadezimal-Integer<br /> local function hex(dec)<br /> local hb = math.floor(dec/16)<br /> local lb = dec%16<br /> if lb &gt; 9 then<br /> lb = string.char(lb +55)<br /> end<br /> if hb &gt; 9 then<br /> hb = string.char(hb +55)<br /> end<br /> return hb .. lb<br /> end<br /> <br /> -- Wandelt einen String so um, dass er innerhalb einer URL verwendet werden kann<br /> -- Dabei werden Leerzeichen durch + ersetzt und andere Sonderzeichen durch ihren Hex-Code<br /> local function transform(code)<br /> local codestring = &quot;&quot;<br /> if code == nil then<br /> return &quot;&quot;;<br /> end<br /> for i = 1, #code, 1 do<br /> local zeichen = code:byte(i)<br /> if (((zeichen &gt;= 48) and (zeichen &lt;=57)) or ((zeichen &gt;= 65) and (zeichen &lt;=90)) or ((zeichen &gt;= 97) and (zeichen &lt;=122))) then<br /> codestring = codestring .. string.char(zeichen)<br /> elseif zeichen == 32 then<br /> codestring = codestring .. &quot;+&quot;<br /> else<br /> codestring = codestring .. &quot;%&quot; .. hex(zeichen)<br /> end<br /> end<br /> return codestring<br /> end<br /> <br /> -- Erzeugt eine URL zum Compiler Explorer<br /> -- für jede &quot;Datei&quot; wird ein Eintrag in den Arrays &quot;code&quot; (der Inhalt der Datei)<br /> -- und &quot;filename&quot; (der Name der Datei) benötigt.<br /> -- Optionen können weggelassen werden. in diesem fall werden Standardwerte benutzt.<br /> local function convert(code, filename, options)<br /> local coptions = &quot;&quot;<br /> local compiler = &quot;cg122&quot;<br /> local execargs = &quot;1&quot;<br /> local execstdin = &quot;1&quot;<br /> local wrap = &quot;1&quot;<br /> local compout = &quot;0&quot;<br /> local cpanel = &quot;0&quot;<br /> <br /> if options ~= nil then<br /> if options.coptions ~= nil then<br /> coptions = options.coptions<br /> end<br /> if options.compiler ~= nil then<br /> compiler = options.compiler<br /> end<br /> if (options.execargs == &quot;1&quot;) or (options.execargs == &quot;0&quot;) then<br /> execargs = options.execargs<br /> end<br /> if (options.execstdin == &quot;1&quot;) or (options.execstdin == &quot;0&quot;) then<br /> execstdin = options.execstdin<br /> end<br /> if (options.wrap == &quot;1&quot;) or (options.wrap == &quot;0&quot;) then<br /> wrap = options.wrap<br /> end<br /> if (options.compout == &quot;1&quot;) or (options.compout == &quot;0&quot;) then<br /> compout = options.compout<br /> end<br /> if (options.cpanel == &quot;1&quot;) or (options.cpanel == &quot;0&quot;) then<br /> cpanel = options.cpanel<br /> end<br /> end<br /> <br /> local url = &quot;https://www.godbolt.org/#g:!((g:!(&quot;<br /> <br /> for i = 1, #filename, 1 do<br /> if filename[i] == &quot;main.c&quot; then<br /> filename[i] = &quot;example.c&quot;<br /> end<br /> url = url .. &quot;(g:!((h:codeEditor,i:(filename:&quot; .. filename[i] .. &quot;,fontScale:14,fontUsePx:&#039;0&#039;,j:&quot; .. i .. &quot;,lang:___c,selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:&#039;&quot; .. transform(code[i]) .. &quot;&#039;),l:&#039;5&#039;,n:&#039;0&#039;,o:&quot; .. filename[i] .. &quot;,t:&#039;0&#039;)),header:(),k:&quot; .. (100/(#filename+1)) .. &quot;,l:&#039;4&#039;,m:100,n:&#039;0&#039;,o:&#039;&#039;,s:0,t:&#039;0&#039;),&quot;<br /> end<br /> <br /> url = url .. &quot;(g:!((g:!((h:tree,i:(cmakeArgs:&#039;&#039;,compilerLanguageId:___c,customOutputFilename:&#039;&#039;,files:!(&quot;;<br /> <br /> for i = 1, #filename, 1 do<br /> url = url .. &quot;(editorId:&quot; .. i .. &quot;,fileId:&quot; .. i .. &quot;,filename:&quot; .. filename[i] .. &quot;,g:&#039;&#039;,isIncluded:&#039;0&#039;,isMainSource:&#039;&quot;<br /> <br /> if filename[i] == &quot;example.c&quot; then <br /> url = url .. &quot;0&quot;<br /> else<br /> url = url ..&quot;1&quot;<br /> end<br /> <br /> url = url .. &quot;&#039;,isOpen:&#039;0&#039;,langId:&#039;&#039;)&quot;<br /> <br /> if i &lt; #filename then<br /> url = url .. &quot;,&quot;<br /> end<br /> end<br /> <br /> url = url .. &quot;),isCMakeProject:&#039;1&#039;,j:1,newFileId:&quot; .. (#filename+1) .. &quot;),l:&#039;5&#039;,n:&#039;0&#039;,o:&#039;Tree+%231&#039;,t:&#039;0&#039;)),header:(),l:&#039;4&#039;,m:50,n:&#039;0&#039;,o:&#039;&#039;,s:0,t:&#039;0&#039;),(g:!((h:executor,i:(argsPanelShown:&#039;&quot; .. execargs .. &quot;&#039;,compilationPanelShown:&#039;&quot; .. cpanel .. &quot;&#039;,compiler:&quot; .. compiler .. &quot;,compilerOutShown:&#039;&quot; .. compout .. &quot;&#039;,execArgs:___,execStdin:&#039;&#039;,fontScale:14,fontUsePx:&#039;0&#039;,j:1,lang:___c,libs:!(),options:&#039;&quot; .. transform(coptions) .. &quot;&#039;,source:&#039;1&#039;,stdinPanelShown:&#039;&quot; .. execstdin .. &quot;&#039;,tree:1,wrap:&#039;&quot; .. wrap .. &quot;&#039;),l:&#039;5&#039;,n:&#039;0&#039;,o:&#039;Executor+(C,+Tree+%231)&#039;,t:&#039;0&#039;)),header:(),k:50,l:&#039;4&#039;,m:50,n:&#039;0&#039;,o:&#039;&#039;,s:0,t:&#039;0&#039;)),k:&quot; .. (100/(#filename+1)) .. &quot;,l:&#039;3&#039;,n:&#039;0&#039;,o:&#039;&#039;,s:0,t:&#039;0&#039;)),l:&#039;2&#039;,n:&#039;0&#039;,o:&#039;&#039;,t:&#039;0&#039;)),version:4&quot;;<br /> <br /> return url<br /> end<br /> <br /> -- Hauptprogramm: Erzeugt einen Link zum Compiler Explorer<br /> -- die Quellcodes müssen in einem Array namens &quot;code&quot; und <br /> -- die Dateinamen in einem Array namens &quot;name&quot; in der Vorlage angegeben werden<br /> -- in der Table &quot;options&quot; können die Optionen<br /> -- coptions, compiler, execargs, execstdin, wrap, compout, cpanel mit anderen Werten belegt werden<br /> -- coptions wird für die Compiler-Optionen verwendet (standardmäßig &quot;&quot;)<br /> -- compiler enthält den Namen des verwendeten Compilers (standardmäßig &quot;cg122&quot;)<br /> -- execargs gibt an, ob die Execution Arguments angezeigt werden (standardmäßig &quot;1&quot;)<br /> -- execstdin gibt an, ob das Execution stdin angezeigt wird (standardmäßig &quot;1&quot;)<br /> -- wrap gibt an, ob es einen automatischen Zeilenumbruch gibt (standardmäßig &quot;1&quot;)<br /> -- compout gibt an, ob der Compiler Output angezeigt wird (standardmäßig &quot;0&quot;)<br /> -- cpanel gibt an, ob die Compiler Options angezeigt werden (standardmäßig &quot;0&quot;)<br /> -- Achtung: eine &quot;1&quot; bedeutet hier &quot;false&quot; und eine &quot;0 &quot;true&quot;<br /> -- Achtung: Innerhalb des Quellcodes nur doppelte Anführungszeichen verwenden,<br /> -- da einfache Anführngszeichen in der URL für die einzelnen Werte verwendet werden.<br /> function CompilerExplorerLink.createLink(frame)<br /> local link = mw.html.create( &quot;a&quot; )<br /> link:attr( &quot;href&quot;, convert(frame.args.code,frame.args.name,frame.args.options) )<br /> :wikitext( linkname )<br /> return tostring( link )<br /> end<br /> <br /> return CompilerExplorerLink</div> Ma.Brauer