The tio-lang is a language that calls to other programming languages that are available on Try It Online.
input:
1
code:
\2brainfuck\x83,+.python\x9Eimport time;time.sleep(int(I))jelly\x88“3ḅaė;œ»c\x84p(a)
>>>
Hello, World!
The current version available is 1.0. This version still does not have an editor for the tio-lang itself. But, tio-lang can be ran easily with a local HTML file and the released code. It also can be embedded into web-pages like here. Probably the more interesting feature of this release is editor.js. This allows one to embed a small editor that communicates to the TIO server for any language not just tio-lang.
<div class="tio-code" tio-language="c-gcc" tio-header="#include <stdio.h>\nint main() {\n" tio-code='printf("Hello, World!\\n")' tio-footer=";return 0;}" tio-hide-header tio-hide-footer tio-js tio-editable tio-runable tio-debug tio-animate-button tio-hide-chars></div>
The tio-lang starts by first reading the initial byte to determine how to interpret the rest of the program. The main three utilize the language identifiers from the TIO servers. This list can be obtained through tio.js and if on the website here.
Once the language identifiers have been paired with the code, it will execute the code. Each ones output feeds as the input into the next one.
The first is the null character \0
which will take the longest possible language identifier immediately following that byte. Then the rest of the code is assumed
to go with that language identifier and runs it.
code:
\0valapublic static int main(string[]args){stdout.printf("Hello, World!\n");return 0;}
>>>
Hello, World!
This is a simple JavaScript library that will execute tio-lang code using tio.js and parser.js. Merely place different attribute names into a <div>
tag
and it will fill everything out as well as remove any child nodes. The class tio-code
is required for it to find the <div>
tag. The function tio_find_editors
can be
called for it to search the DOM and process these elements. The function tio_apply_editor
can be called while providing an HTML element with the appropriate attributes set
and it will properly generate the HTML content for the editor in said element.
<div class="tio-code" tio-code='\0ada-gnatwith Ada.Text_IO;use Ada.Text_IO;procedure Main is begin Put_Line ("Yeah!");end Main;' tio-input="" tio-runable="I'm a goofy goober!" tio-animate-button></div>
Sets the tio-lang code to be executed.
Sets the input into the tio-lang program to be executed.
Sets the type of HTML to be generated. The default is current "code" and the only type that has been tested.
If provided, it will add the debug output from the TIO servers to the end of the output.
Adds a button to the HTML elements that will execute the code. If not provided, the code will begin executing immediately. The text of button is set to the value provided where the default is
{RUN}
. If the value is{RUN}
then it will generate the button as a small circle.
A small animation sequence will be added while the program is executing. If not set, there will be no animation added to the code.
A small animation sequence will be added while the program is running for the button. If not set, there will be no animation.
If provided, the editor created will not run tio-lang. Instead, it will execute a normal tio.js session.
<div tio-language="python3" class="tio-code" tio-code='print(":)", sys.argv, sys.stdin.read())' tio-header="import sys;import time;time.sleep(2)" tio-footer="" tio-input="" tio-args="" tio-runable tio-animate-button tio-js tio-editable tio-debug></div>
Makes all fields editable if
tio-js
andtio-runable
are provided.
Sets the header code for the session if
tio-js
is provided.
Sets the footer code for the session if
tio-js
is provided.
Sets the args list for the session if
tio-js
is provided. This must be a JavaScript Array like object.
Sets the options list for the session if
tio-js
is provided. This must be a JavaScript Array like object.
Sets the drivers list for the session if
tio-js
is provided. This must be a JavaScript Array like object.
Sets the language for the session if
tio-js
is provided. This must be a language identifier. Once it has been confirmed to be a valid language id, it will change to printing the language name.
Allows the
tio-input
to still be parsed, but it will not be displayed.
Allows the
tio-header
to still be parsed, but it will not be displayed.
Allows the
tio-footer
to still be parsed, but it will not be displayed.
Allows the
tio-args
to still be parsed, but it will not be displayed.
Allows the
tio-options
to still be parsed, but it will not be displayed.
Allows the
tio-drivers
to still be parsed, but it will not be displayed.
Allows the
tio-language
to still be parsed, but it will not be displayed.
Prevents the
[bytes]
from being displayed.
Prevents the
[chars]
from being displayed.
There is an API provided by tio-lang that allows one to interface with the TIO servers. It is the main utility used in order to provide the multi-language language. The following are the javascript files to include in order to get this API.
https://tkellehe.github.io/tio-lang/src/js/pako.js
https://tkellehe.github.io/tio-lang/src/js/tio.js
For more info on these dependencies:
tio.onload.add(function() {
console.log("Number of languages: " + tio.utils.languages.length);
tio.language("python3");
tio.code("import sys\nprint(sys.argv)");
tio.args.push('-t');
tio.onsetoutput.add(function() {
console.log("Server output: " + tio.output());
});
tio.run();
});
tio.load();
tio.language("jelly")
tio.code("“3ḅaė;œ»")
tio.oncomplete.add(function() {
tio.alert(tio.output());
tio.alert(tio.debug());
});
tio.run()
A global set of information used throughout all
Session
instances created.
The list of language JSON objects pulled from the TIO servers.
Takes in a name and attempts to find the closest matches to that while ignoring case. It then returns these as an array.
Checks if the language identifier is valid.
Encodes a string into a byte string.
Decodes a byte string into a string.
Compress byte string in order to send to the TIO servers.
Decompress byte array from TIO servers.
Counts the bytes based on the encoding provided. The different options are:
SBCS
,UTF-8
,nibbles
,xxd
Count the number of characters in the code which is the same as
tio.utils.count_bytes(code, "SBCS")
.
Takes the
eventHandler
object provided and adds the functionsaddEventListener
andremoveEventListener
. These functions can take in an event already added, and either add a function or remove a function. Note that the name utilize for the event will have the prefix"on"
added. Also,addEventListener
can be provided an additional argument that if providedfalse
will remove added function after is has be activated once for that event. If theevent
name is provided, it will add an extra attribute to theeventHandler
as the string value provided. This new attribute is the event function that when invoked, will take the optionalevent_instance
and pass it to all of the functions that have been added. This function also has the attributesadd
andremove
which work the same asaddEventListener
andremoveEventListener
except that it defaults the the event name to be this attributes name.The function also returns an object created with the appropriate attributes added with an extra of
onevent
that will immediately invoke the event. It also has an attribute ofeventType
set to auto-generatedeventType
or the one provided.The
eventType
can be provided which will be auto-generated if not provided. This is used to construct theevent_instance
passed to all of the event functions registered. The default auto-generated function caches all arguments provided upon construction into theargs
attribute of the instance.
var obj = {};
tio.utils.onlistener(obj, "myevent");
function f(e){console.log(e)}
obj.myevent.add(f);
obj.myevent();
obj.myevent.remove(f);
Create a new
Session
instance that can communicate and run code. Also,tio
is aSession
instance.
An array of messages that have been sent out. The callback
onmessage
can be used to know when this changes.
An array of settings for the TIO server.
An array of string options for the language to be sent to the TIO server.
An array of string cflags for the language to be sent to the TIO server.
An array of string drivers for the language to be sent to the TIO server.
An array of string arguments for language to be sent to the TIO server.
Loads the languages from the TIO servers and populates the
tio.utils
data. The callbackonload
can be used to be notified when the data is brought in. Ifforce
is set to true, it will call the callback if the data is there else it will behave normally. Rather that theforce
ensure another fetch is called to the TIO servers, this was done because that can become quite expensive. Therein,fetch
was added to ensure another fetch to the TIO servers.
Forces a fetch to the TIO servers and populates the
tio.utils
data. The callbackonload
can be used to be notified when the data is brought in.
Caches the message into the
Session.messages
array with aMessage
object.
Invoke all clear functions for
Session
instance.
Clears all of the messages in the
Session.messages
array.
Clears both
Session.output
andSession.debug
triggering callbacksonsetoutput
andonsetdebug
.
Clears all input related information which includes
Session.options
,Session.args
,Session.cflags
,Session.driver
, and invokes callbackonsetinput
.
Returns a markdown representation of the code.
Get the message that encodes the current state of the
Session
instance that will be sent to the TIO servers.
Packages up the code and options to be sent to the TIO servers. If invoked again, it will cancel the previous run and start a new one. The callbacks that can be used to access this:
onrun
,oncancel
,oncomplete
Cancels a previous request made to the TIO servers to execute some code. Will invoke the callback
oncancel
if cancellation occurred.
Counts the number of bytes in
Session.code()
based on the selected language.
Counts the number of characters in the
Session.code()
.
Sets the language if an argument is provided, else it will return the current language stored. The callbacks
onsetlanguage
andongetlanguage
get called based on the argument. If the languages have been loaded, this will also add the propertiesoptions
,cflags
, anddriver
based off of the umask information from the TIO servers.
Sets the header if an argument is provided, else it will return the current header stored. The callbacks
onsetheader
andongetheader
get called based on the argument.
Sets the code if an argument is provided, else it will return the current code stored. The callbacks
onsetcode
andongetcode
get called based on the argument.
Sets the footer if an argument is provided, else it will return the current footer stored. The callbacks
onsetfooter
andongetfooter
get called based on the argument.
Sets the input if an argument is provided, else it will return the current input stored. The callbacks
onsetinput
andongetinput
get called based on the argument.
Sets the output if an argument is provided, else it will return the current output stored. The callbacks
onsetoutput
andongetoutput
get called based on the argument.
Sets the debug if an argument is provided, else it will return the current debug stored. The callbacks
onsetdebug
andongetdebug
get called based on the argument.
<script src="src/js/pako.js"></script> <script src="src/js/tio.js"></script> <script src="src/js/parser.js"></script> <script src="src/js/editor.js"></script>
Languages: