int luab_NetMatch_get_player_count(lua_State *L) {
    NetMatch *match = luaL_tonetmatch(L, 1);
    check(match != NULL, "NetMatch required");

    if (match->proto.get_player_count) {
        Engine *engine = luaL_get_engine(L);
        int count = match->_(get_player_count)(match, engine);
        lua_pushinteger(L, count);
    } else {
        luaL_error(L, "Method not supported on this platform.");
    }
    return 1;
error:
    return 0;
}
int luab_NetMatch_new(lua_State *L) {
    NetMatch_userdata *ud = NULL;
    Engine *engine = luaL_get_engine(L);

    ud = lua_newuserdata(L, sizeof(NetMatch_userdata));
    check(ud != NULL, "Could not make NetMatch userdata");
    ud->p = NULL;

    luaL_getmetatable(L, luab_NetMatch_metatable);
    lua_setmetatable(L, -2);

    NetMatch *match = NetMatch_create(engine);
    luaL_register_ud(L, -1, (void **)&ud->p, match);
    return 1;
error:
    return 0;
}
int luab_NetMatch_send_null_msg(lua_State *L) {
    NetMatch *match = luaL_tonetmatch(L, 1);
    check(match != NULL, "NetMatch required");

    if (match->proto.send_msg) {
        lua_Integer to = lua_tointeger(L, 2);
        NetMatchMsg *msg = NetMatchMsg_null(0, to);

        Engine *engine = luaL_get_engine(L);
        match->_(send_msg)(match, engine, msg);

        NetMatchMsg_destroy(msg);
    } else {
        luaL_error(L, "Method not supported on this platform.");
    }
    return 0;
error:
    return 0;
}
int luab_ParallaxLayer_new(lua_State *L) {
    ParallaxLayer_userdata *ud = NULL;
    Engine *engine = luaL_get_engine(L);

    ud = lua_newuserdata(L, sizeof(ParallaxLayer_userdata));
    check(ud != NULL, "Could not make ParralaxLayer userdata");

    luaL_getmetatable(L, luab_ParallaxLayer_metatable);
    lua_setmetatable(L, -2);

    const char *texname = lua_tostring(L, -2);
    GfxTexture *tex = Graphics_texture_from_image(engine->graphics,
            (char *)texname);
    check(tex != NULL, "Couldn't load image %s", texname);

    ParallaxLayer *layer = ParallaxLayer_create(tex);

    luaL_register_ud(L, -1, (void **)&ud->p, layer);
    return 1;
error:
    return 0;
}