https://de.wikipedia.org/w/index.php?action=history&feed=atom&title=Modul%3ACompilerExplorerLinkModul:CompilerExplorerLink - Versionsgeschichte2025-06-07T15:58:39ZVersionsgeschichte dieser Seite in WikipediaMediaWiki 1.45.0-wmf.4https://de.wikipedia.org/w/index.php?title=Modul:CompilerExplorerLink&diff=228612952&oldid=prevMa.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 > 9 then<br />
lb = string.char(lb +55)<br />
end<br />
if hb > 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 = ""<br />
if code == nil then<br />
return "";<br />
end<br />
for i = 1, #code, 1 do<br />
local zeichen = code:byte(i)<br />
if (((zeichen >= 48) and (zeichen <=57)) or ((zeichen >= 65) and (zeichen <=90)) or ((zeichen >= 97) and (zeichen <=122))) then<br />
codestring = codestring .. string.char(zeichen)<br />
elseif zeichen == 32 then<br />
codestring = codestring .. "+"<br />
else<br />
codestring = codestring .. "%" .. hex(zeichen)<br />
end<br />
end<br />
return codestring<br />
end<br />
<br />
-- Erzeugt eine URL zum Compiler Explorer<br />
-- für jede "Datei" wird ein Eintrag in den Arrays "code" (der Inhalt der Datei)<br />
-- und "filename" (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 = ""<br />
local compiler = "cg122"<br />
local execargs = "1"<br />
local execstdin = "1"<br />
local wrap = "1"<br />
local compout = "0"<br />
local cpanel = "0"<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 == "1") or (options.execargs == "0") then<br />
execargs = options.execargs<br />
end<br />
if (options.execstdin == "1") or (options.execstdin == "0") then<br />
execstdin = options.execstdin<br />
end<br />
if (options.wrap == "1") or (options.wrap == "0") then<br />
wrap = options.wrap<br />
end<br />
if (options.compout == "1") or (options.compout == "0") then<br />
compout = options.compout<br />
end<br />
if (options.cpanel == "1") or (options.cpanel == "0") then<br />
cpanel = options.cpanel<br />
end<br />
end<br />
<br />
local url = "https://www.godbolt.org/#g:!((g:!("<br />
<br />
for i = 1, #filename, 1 do<br />
if filename[i] == "main.c" then<br />
filename[i] = "example.c"<br />
end<br />
url = url .. "(g:!((h:codeEditor,i:(filename:" .. filename[i] .. ",fontScale:14,fontUsePx:'0',j:" .. i .. ",lang:___c,selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:'" .. transform(code[i]) .. "'),l:'5',n:'0',o:" .. filename[i] .. ",t:'0')),header:(),k:" .. (100/(#filename+1)) .. ",l:'4',m:100,n:'0',o:'',s:0,t:'0'),"<br />
end<br />
<br />
url = url .. "(g:!((g:!((h:tree,i:(cmakeArgs:'',compilerLanguageId:___c,customOutputFilename:'',files:!(";<br />
<br />
for i = 1, #filename, 1 do<br />
url = url .. "(editorId:" .. i .. ",fileId:" .. i .. ",filename:" .. filename[i] .. ",g:'',isIncluded:'0',isMainSource:'"<br />
<br />
if filename[i] == "example.c" then <br />
url = url .. "0"<br />
else<br />
url = url .."1"<br />
end<br />
<br />
url = url .. "',isOpen:'0',langId:'')"<br />
<br />
if i < #filename then<br />
url = url .. ","<br />
end<br />
end<br />
<br />
url = url .. "),isCMakeProject:'1',j:1,newFileId:" .. (#filename+1) .. "),l:'5',n:'0',o:'Tree+%231',t:'0')),header:(),l:'4',m:50,n:'0',o:'',s:0,t:'0'),(g:!((h:executor,i:(argsPanelShown:'" .. execargs .. "',compilationPanelShown:'" .. cpanel .. "',compiler:" .. compiler .. ",compilerOutShown:'" .. compout .. "',execArgs:___,execStdin:'',fontScale:14,fontUsePx:'0',j:1,lang:___c,libs:!(),options:'" .. transform(coptions) .. "',source:'1',stdinPanelShown:'" .. execstdin .. "',tree:1,wrap:'" .. wrap .. "'),l:'5',n:'0',o:'Executor+(C,+Tree+%231)',t:'0')),header:(),k:50,l:'4',m:50,n:'0',o:'',s:0,t:'0')),k:" .. (100/(#filename+1)) .. ",l:'3',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4";<br />
<br />
return url<br />
end<br />
<br />
-- Hauptprogramm: Erzeugt einen Link zum Compiler Explorer<br />
-- die Quellcodes müssen in einem Array namens "code" und <br />
-- die Dateinamen in einem Array namens "name" in der Vorlage angegeben werden<br />
-- in der Table "options" 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 "")<br />
-- compiler enthält den Namen des verwendeten Compilers (standardmäßig "cg122")<br />
-- execargs gibt an, ob die Execution Arguments angezeigt werden (standardmäßig "1")<br />
-- execstdin gibt an, ob das Execution stdin angezeigt wird (standardmäßig "1")<br />
-- wrap gibt an, ob es einen automatischen Zeilenumbruch gibt (standardmäßig "1")<br />
-- compout gibt an, ob der Compiler Output angezeigt wird (standardmäßig "0")<br />
-- cpanel gibt an, ob die Compiler Options angezeigt werden (standardmäßig "0")<br />
-- Achtung: eine "1" bedeutet hier "false" und eine "0 "true"<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( "a" )<br />
link:attr( "href", 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