Read-o-meter BLiP

What I do

I make websites, simulations and the occasional game or two. I specialise in functional websites, but I can make display websites.

I've made a few websites. Some I make for friends, others for people who want them. Usually, I can do it for free.

I've made Read-o-meter, a website with ~400 users, and BLiP - one I'm quite proud of design-wise. I also make other little websites as well, like my bibliography generator, and some very quick (i.e. not very good) ones, like my Multiplication Connect 4.

If you want, contact me. I'm usually happy to help - especially for a good cause :)

My blog

Very occasional opinions and news about my projects and other things.

Using recursive functions to return a table visulized as a string in Lua

Friday 20th October 2017 at 21:40pm

Trying to print a table in Lua will give you something like table: 1x0324421.
This function takes a table and returns it as it would appear in code.

function tableAsString(tbl)
	toReturn = "{"
	for ind, val in pairs(tbl) do
		if type(val) == "table" then
			toReturn = toReturn .. (type(ind) == "number" and "" or ind .. "=") .. tableAsString(val) .. ","
			local newVal
			if type(val) == "string" then
				newVal = "\"" .. val .. "\""
				newVal = val
			toReturn = toReturn .. (type(ind) == "number" and "" or ind .. "=") .. newVal .. ","
	toReturn = toReturn:sub(1,-2) .. "}" -- remove trailing "," and close table
	return toReturn
Since every table starts with a "{", this is the start of the returned string.
After this, every value is looped through. If it's a value (string/number) it's appended to the return string, with it's index if it's not a number (numbers are considered to be automatic indices). If it's a table, then it needs to be displayed as one, so instead of appending the value, we need a table string: so we recursively call the function with the table that needs to be a string as the parameter. If that table contains more tables, they will be dealt with recursively. Finally, before closing the table, any trailing commas are removed.

Scale choosing tool

Saturday 12th March 2016 at 19:54pm

Have an instrument exam coming up? Try my scale chooser to test yourself. Currently, it has a limited selection of grades, but when I can, I will add more grades and hopefully instruments. Try it out!

View all posts