mirror of
https://github.com/MinetestForFun/mysql_base.git
synced 2024-12-27 18:10:24 +01:00
Improve a bit the code...
..., remove one deprecated function, use mod.conf for name and description.
This commit is contained in:
parent
124bdb7401
commit
1a36d6a7d5
@ -1,5 +1,4 @@
|
|||||||
local modname = minetest.get_current_modname()
|
local modname = minetest.get_current_modname()
|
||||||
|
|
||||||
local thismod = _G[modname]
|
local thismod = _G[modname]
|
||||||
|
|
||||||
---- Table creation & deletion
|
---- Table creation & deletion
|
||||||
@ -33,6 +32,7 @@ function thismod.create_table_sql(name, params)
|
|||||||
end
|
end
|
||||||
return 'CREATE TABLE ' .. name .. ' (' .. table.concat(lines, ',') .. ')'
|
return 'CREATE TABLE ' .. name .. ' (' .. table.concat(lines, ',') .. ')'
|
||||||
end
|
end
|
||||||
|
|
||||||
function thismod.create_table(name, params)
|
function thismod.create_table(name, params)
|
||||||
thismod.conn:query(thismod.create_table_sql(name, params))
|
thismod.conn:query(thismod.create_table_sql(name, params))
|
||||||
end
|
end
|
||||||
@ -40,6 +40,7 @@ end
|
|||||||
function thismod.drop_table_sql(name)
|
function thismod.drop_table_sql(name)
|
||||||
return 'DROP TABLE ' .. name
|
return 'DROP TABLE ' .. name
|
||||||
end
|
end
|
||||||
|
|
||||||
function thismod.drop_table(name)
|
function thismod.drop_table(name)
|
||||||
thismod.conn:query(thismod.drop_table_sql(name))
|
thismod.conn:query(thismod.drop_table_sql(name))
|
||||||
end
|
end
|
||||||
@ -96,6 +97,7 @@ end
|
|||||||
function thismod.prepare_select_sql(tablename, colnames, where)
|
function thismod.prepare_select_sql(tablename, colnames, where)
|
||||||
return 'SELECT ' .. table.concat(colnames, ',') .. ' FROM ' .. tablename .. ' WHERE ' .. where
|
return 'SELECT ' .. table.concat(colnames, ',') .. ' FROM ' .. tablename .. ' WHERE ' .. where
|
||||||
end
|
end
|
||||||
|
|
||||||
function thismod.prepare_select(tablename, cols, where, wheretypes)
|
function thismod.prepare_select(tablename, cols, where, wheretypes)
|
||||||
local colnames, coltypes = {}, {}
|
local colnames, coltypes = {}, {}
|
||||||
for _, col in ipairs(cols) do
|
for _, col in ipairs(cols) do
|
||||||
@ -104,4 +106,4 @@ function thismod.prepare_select(tablename, cols, where, wheretypes)
|
|||||||
end
|
end
|
||||||
local stmt = thismod.conn:prepare(thismod.prepare_select_sql(tablename, colnames, where))
|
local stmt = thismod.conn:prepare(thismod.prepare_select_sql(tablename, colnames, where))
|
||||||
return stmt, stmt:bind_params(wheretypes), stmt:bind_result(coltypes)
|
return stmt, stmt:bind_params(wheretypes), stmt:bind_result(coltypes)
|
||||||
end
|
end
|
7
init.lua
7
init.lua
@ -11,12 +11,14 @@ function thismod.mklog(level, modname)
|
|||||||
minetest.log(level, "[" .. modname .. "] " .. str)
|
minetest.log(level, "[" .. modname .. "] " .. str)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local LogI = thismod.mklog('action', modname)
|
local LogI = thismod.mklog('action', modname)
|
||||||
local LogE = thismod.mklog('error', modname)
|
local LogE = thismod.mklog('error', modname)
|
||||||
|
|
||||||
local singleplayer = minetest.is_singleplayer() -- Caching is OK since you can't open a game to
|
local singleplayer = minetest.is_singleplayer() -- Caching is OK since you can't open a game to
|
||||||
-- multiplayer unless you restart it.
|
-- multiplayer unless you restart it.
|
||||||
if minetest.setting_get(modname .. '.enable_singleplayer') ~= 'true' and singleplayer then
|
|
||||||
|
if minetest.settings:get(modname .. '.enable_singleplayer') ~= 'true' and singleplayer then
|
||||||
LogI("Not enabling because of singleplayer game")
|
LogI("Not enabling because of singleplayer game")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -202,6 +204,7 @@ local function ping()
|
|||||||
end
|
end
|
||||||
minetest.after(1800, ping)
|
minetest.after(1800, ping)
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.after(10, ping)
|
minetest.after(10, ping)
|
||||||
|
|
||||||
local shutdown_callbacks = {}
|
local shutdown_callbacks = {}
|
||||||
@ -229,4 +232,4 @@ function thismod.table_exists(name)
|
|||||||
return exists
|
return exists
|
||||||
end
|
end
|
||||||
|
|
||||||
dofile(modpath .. '/abstraction.lua')
|
dofile(modpath .. '/abstraction.lua')
|
Loading…
Reference in New Issue
Block a user