No Description

IVogel d413c024fe `ptr::drop_in_place` looks (and works) a bit better I think 2 years ago
src d413c024fe `ptr::drop_in_place` looks (and works) a bit better I think 2 years ago
.gitignore 7a811cc309 initial commit 2 years ago
Cargo.toml f0d6504eb9 Changed version 2 years ago
README.md 13e857d66b This should be a bit easier now, I guess. 2 years ago
build.rs 7a811cc309 initial commit 2 years ago

README.md

gm_sled

gm_sled is really simple wrapper around sled key-value database.

Installation

Download latest binary for corresponding OS and throw it into garrysmod/lua/bin/.
Or, you can compile your own version.

Compilation for main Garry's Mod branch:

cargo build --release --target i686-unknown-linux-gnu

or for windows

cargo build --release --target i686-pc-windows-msvc

Compilation for x86-x64 branch:

cargo build --release --target x86_64-unknown-linux-gnu

or for windows

cargo build --release --target x86_64-pc-windows-msvc

Example usage (but not really good example)

require("sled")

local db = sled.Open("currencydb")

currencydb = {__currency = {}}

function currencydb.set(player, currency, value)
    local tree = currencydb.__currency[currency]
    if not tree then
        tree = db:OpenTree(currency)
        currencydb.__currency[currency] = tree
    end
    tree:InsertStruct(player:SteamID64(), "d", value)
end

function currencydb.get(player, currency)
    local tree = currencydb.__currency[currency]
    if not tree then
        tree = db:OpenTree(currency)
        currencydb.__currency[currency] = tree
    end
    return tree:GetStruct(player:SteamID64(), "d")
end

function currencydb.list()
    local names = {}
    for name in db:TreeNames() do
        if name == "__sled__default" then continue end
        table.insert(names, name)
    end
    return names
end