Category Archives: Lua

Rocket: A Lua Sqlite3 ORM manager

Relational databases are designed so that they can both store and describe data. Most programming level APIs do wonderful jobs of maintaining the former aspect. I mean, what ORM doesn’t automatically map the insert method to the so very generic…

Posted in Blog, Lua, Programming, Snippets | Tagged , , , , , , , | Leave a comment

See.lua – Documentation

See.lua – A Lua introspection library

	> see(string)

	.byte(?)            .char(?)            .dump(?)            .find(?)
	.format(?)          .gfind(?)           .gmatch(?)          .gsub(?)
	.join(self, table, ...)                 .len(?)
	.lower(?)           .match(?)           .rep(?)             .reverse(?)
	.sub(?)             .upper(?)

Lua is a wonderful little language that lets you do…

Posted in Blog, Lua, Programming, Snippets | Tagged , , , | Leave a comment

see.lua – Introspecting Lua objects

As via its python equivalent, see.lua takes in an object and prints out a list of its elements as well as metatable methods in readable text.

> require "see"

> s = see(string)
.byte(?)            .char(?)            .dump(?)            .find(?)

Posted in Blog, Lua, Programming, Snippets | Tagged , , , , , , | 1 Comment

Tips and Tricks for Lua Beginners: Writing an at.exit registry

It’s relatively simple to write a function that takes in a function and executes it once Lua terminates.

at = {}
function at.exit(fn)
     getmetatable(newproxy(true)).__gc = fn
end
Posted in Blog, Lua, Programming, Snippets | Tagged , , , , , , | Leave a comment

Lua – Get a table of function arguments

The lua standard libraries do not provide anything that helps you get the table of arguments for a given function. This can be accomplished by directly introspecting the bytecode of the function. The following snippet generates a function get_args that…

Posted in Blog, Lua, Programming, Snippets | Tagged , , , , , , | Leave a comment

Lua – Get number of parameters in a function

The following snippet defines a function num_args(func) that returns the number of parameters within a function as a string:

num_args(function(a,b,c) end) --> 3

It also works with functions that have variable arguments:

num_args(function(a,...)

Posted in Blog, Lua, Programming, Snippets | Tagged , , , , | Leave a comment

Serializing Lua objects into Lua Code

The following little snippet allows you to ‘pickle’ Lua objects directly into Lua code (with the exception of functions, which are serialized as raw bytecode). Metatable support is on the way, but for now, it should be useful enough.

Example

Posted in Blog, Lua, Programming, Snippets | Tagged , , , , , , | 1 Comment

Lua Exception Handling

Wouldn’t it be awsome if you could do something like

dofile "try"

try{
	function()
		a = a/a
	end
}.except(Exceptions.ValueError){
	function(_, exceptions, detail)
		print(detail)
	end
}

And get

lua:5: attempt to perform arithmetic on

Posted in Blog, Lua, Programming, Snippets | Tagged , , , , | 2 Comments