Archives for March 2011

Some Uses for the Modulos Operator (%)

Posted on March 21, 2011 in Tutorials

I've been learning about a few of the awesome things you can do with the modulos operator lately. For those who don't know, the modulos operator (the percent symbol in code) gives the remainder of dividing two numbers. Therefore, 10 % 4 equals 2, because 4 goes into 10 two times, and what we have left is the number 2. Now let's get into what we can do (note, I'll be using Ruby code here,...

Read more...

Simulate Bitwise Shift Operators in Lua

Posted on March 21, 2011 in Tutorials

EDIT: Here's a couple functions which will do the shift operations that I've put in gist #938502. The fact that Lua doesn't have bitwise operators is a pain. There are pure Lua implementations out there, such as LuaBit, but I find these to be a little slow (I think LuaBit using tables or something like that). I've found a way to simulate both the left-shift and right-shift operator by using some simple mathematics. Left-Shift By...

Read more...

Unix Utils

Posted on March 18, 2011 in Projects

I've opened up a new repository on GitHub called unix-utils. This repository is to be host for the utility commands for the terminal I "have/might/will" make. Currently it only contains one, which is called strlen. Since I've already written about in the README, I'll point you over there for more information.

Read more...

ClosureClass

Posted on March 13, 2011 in Projects

I've recently created an experimental Lua object-orientation library using the closure approach to OOP. It's based largely on MiddleClass, sharing a lot of design features with it. I've already written a README, so go and visit the GitHub repo for more information.

Read more...

MiddleClass Extensions

Posted on March 11, 2011 in Projects

I've just recently opened up a new repository at GitHub called middleclass-extensions, which contains my personal hacks, extensions, extras, whatever you want to call them, to MiddleClass. It's a bit like middleclass-extras. So far the repo only contains one extensions, called Static, but this will grow over time. Static is about creating class only methods. When you create a method which you intend to be accessed only via the class, MiddleClass has no way to...

Read more...

Mixin Inheritance in MiddleClass

Posted on March 09, 2011 in Tutorials

The technique I'm about to present, may seem obvious, but I'll share it anyway. The way I would create mixins that inherit stuff from other mixins is this: Mixin = {} function Mixin:included(class) if not includes(ParentMixin, class) then class:include(ParentMixin) end end When the mixin is included, it will check whether the class includes the mixin, and if not, it will include it, therefore simulating inheritance. It's good to check if the class includes the parent...

Read more...

Sometimes WebKit Makes a Big Difference

Posted on March 08, 2011 in General

Due to all the awesome features that WebKit has to offer, if you're not using a WebKit browser, some pages can look very different and you don't even know. Take a look at the awesomely constructed under construction (I know, that sounds weird) page at ringshia.com. If you view it in a WebKit based browser (Chrome and Safari are the major ones) you'll see some nice looking text (using text shadows), a background gradient, and...

Read more...

Lua Performance Tests

Posted on March 08, 2011 in General

Just for some experimentation, I did some performance tests on a few operations in Lua. To time them I used the command, time lua test.lua, and took the "real" time. The test file was just a loop, which looped 20 million times: for i = 1, 20000000 do --[[ code here ]] end Alright, here's the results. Description Seconds Loop Code Variable/Function Definition Empty function call 1.249 f() function f() end Return function call 1.688...

Read more...

Singleton Class in MiddleClass (Lua)

Posted on March 07, 2011 in Tutorials

I thought I'd demonstrate a method for making a singleton class in MiddleClass. If you don't know, MiddleClass is an object-orientation library for Lua. So why would you want to make a class that only has one instance with MiddleClass? Couldn't you just use a table? Well, making it a class in MiddleClass allows you to take advantage of a number of other cool things that MiddleClass has on offer, like mixins, inheritance and so...

Read more...