summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim <t4im@users.noreply.github.com>2015-02-05 10:03:07 +0100
committerTim <t4im@users.noreply.github.com>2015-02-05 10:03:07 +0100
commit76a9efff71f924b143af8945ce02ed336b6a1090 (patch)
treeb784af07779fa7ce096a398e6665293b41d28572
parent1a1bfc3839ccd3001b4f446b5ad230711fd258b1 (diff)
reduce table lookups during initialization
-rw-r--r--api.lua7
-rw-r--r--bags.lua7
-rw-r--r--init.lua56
-rw-r--r--internal.lua7
-rw-r--r--register.lua7
-rw-r--r--waypoints.lua7
6 files changed, 35 insertions, 56 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 <cornernote@gmail.com>
-- 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 = {}
-
--- Homepos stuff
-unified_inventory.home_pos = {}
-unified_inventory.home_filename =
- worldpath.."/unified_inventory_home.home"
-
--- Default inventory page
-unified_inventory.default = "craft"
+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
+ home_pos = {},
+ home_filename = worldpath.."/unified_inventory_home.home",
+
+ -- 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")},