From 76a9efff71f924b143af8945ce02ed336b6a1090 Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 5 Feb 2015 10:03:07 +0100 Subject: [PATCH] reduce table lookups during initialization --- api.lua | 7 +------ bags.lua | 7 +------ init.lua | 52 +++++++++++++++++++++++++++------------------------ internal.lua | 7 +------ register.lua | 7 +------ waypoints.lua | 7 +------ 6 files changed, 33 insertions(+), 54 deletions(-) diff --git a/api.lua b/api.lua index 7ee5b9e..b338cfb 100644 --- a/api.lua +++ b/api.lua @@ -1,9 +1,4 @@ -local S -if rawget(_G, "intllib") then - S = intllib.Getter() -else - S = function(s) return s end -end +local S = unified_inventory.gettext -- Create detached creative inventory after loading all mods minetest.after(0.01, function() diff --git a/bags.lua b/bags.lua index b2ef757..cb568f8 100644 --- a/bags.lua +++ b/bags.lua @@ -3,12 +3,7 @@ -- Copyright (c) 2012 cornernote, Brett O'Donnell -- License: GPLv3 -local S -if rawget(_G, "intllib") then - S = intllib.Getter() -else - S = function(s) return s end -end +local S = unified_inventory.gettext unified_inventory.register_page("bags", { get_formspec = function(player) diff --git a/init.lua b/init.lua index 85bf293..ebc5fda 100644 --- a/init.lua +++ b/init.lua @@ -3,33 +3,37 @@ local modpath = minetest.get_modpath(minetest.get_current_modname()) local worldpath = minetest.get_worldpath() + -- Data tables definitions -unified_inventory = {} -unified_inventory.activefilter = {} -unified_inventory.active_search_direction = {} -unified_inventory.alternate = {} -unified_inventory.current_page = {} -unified_inventory.current_searchbox = {} -unified_inventory.current_index = {} -unified_inventory.current_item = {} -unified_inventory.current_craft_direction = {} -unified_inventory.registered_craft_types = {} -unified_inventory.crafts_for = { usage = {}, recipe = {} } -unified_inventory.players = {} -unified_inventory.items_list_size = 0 -unified_inventory.items_list = {} -unified_inventory.filtered_items_list_size = {} -unified_inventory.filtered_items_list = {} -unified_inventory.pages = {} -unified_inventory.buttons = {} +unified_inventory = { + activefilter = {}, + active_search_direction = {}, + alternate = {}, + current_page = {}, + current_searchbox = {}, + current_index = {}, + current_item = {}, + current_craft_direction = {}, + registered_craft_types = {}, + crafts_for = {usage = {}, recipe = {} }, + players = {}, + items_list_size = 0, + items_list = {}, + filtered_items_list_size = {}, + filtered_items_list = {}, + pages = {}, + buttons = {}, --- Homepos stuff -unified_inventory.home_pos = {} -unified_inventory.home_filename = - worldpath.."/unified_inventory_home.home" + -- Homepos stuff + home_pos = {}, + home_filename = worldpath.."/unified_inventory_home.home", --- Default inventory page -unified_inventory.default = "craft" + -- Default inventory page + default = "craft", + + -- intllib + gettext = rawget(_G, "intllib") and intllib.Getter() or function(s) return s end, +} -- Disable default creative inventory if rawget(_G, "creative_inventory") then diff --git a/internal.lua b/internal.lua index 50150b7..47a9171 100644 --- a/internal.lua +++ b/internal.lua @@ -1,9 +1,4 @@ -local S -if rawget(_G, "intllib") then - S = intllib.Getter() -else - S = function(s) return s end -end +local S = unified_inventory.gettext -- This pair of encoding functions is used where variable text must go in -- button names, where the text might contain formspec metacharacters. diff --git a/register.lua b/register.lua index 5a77bc0..3f0d27c 100644 --- a/register.lua +++ b/register.lua @@ -1,9 +1,4 @@ -local S -if rawget(_G, "intllib") then - S = intllib.Getter() -else - S = function(s) return s end -end +local S = unified_inventory.gettext minetest.register_privilege("creative", { description = "Can use the creative inventory", diff --git a/waypoints.lua b/waypoints.lua index aef9a2f..890c3ec 100644 --- a/waypoints.lua +++ b/waypoints.lua @@ -1,9 +1,4 @@ -local S -if rawget(_G, "intllib") then - S = intllib.Getter() -else - S = function(s) return s end -end +local S = unified_inventory.gettext local hud_colors = { {"#FFFFFF", 0xFFFFFF, S("White")},