stevedonovan/luar — pull request #2 by kdar (2013-03-22 02:00:11+00:00)
Title: Added support for "errors" in GoToLua().

Now you can do stuff like return an error from a function in Go or call a Lua callback with an error parameter.

e.g.

func hello() error {
return errors.New("error occurred")
}

luar.Register(L, "", luar.Map{
"hello": hello
})

and then in Lua:

err = hello()
if err ~= nil then
print(err)
end

I also ran it through the default "go fmt".

The relevant piece of code is:

case reflect.Struct:
{
if v, ok := val.Interface().(error); ok {
L.PushString(v.Error())
} else {
makeValueProxy(L, val, STRUCT_META)
}
}
default:
{
if v, ok := val.Interface().(error); ok {
L.PushString(v.Error())
} else if val.IsNil() {
L.PushNil()
} else {
makeValueProxy(L, val, INTERFACE_META)
}
}