What's new

Lua Functions [LIB] Kilka dodatk?w do 012-table.lua

Status
Not open for further replies.

Gandhi

Active User
Joined
Aug 7, 2013
Messages
80
Reaction score
19
Siemka. Podziel? si? z wami moimi dodatkowymi funkcjami do liba tabel. Opis funkcji pod skryptem.

Doda? na sam sp?d pliku data/lib/012-table.lua:
[lua]function table.unpack(t, sep, sepLast)
local str = ''
for i, v in ipairs(t) do
str = str .. (i > 1 and (i == #t and sepLast or sep) or '') .. v
end
return str
end

function table.merge(f, s)
for k, v in pairs(s) do
f[k] = v
end
end

function table.shuffle(t)
math.randomseed(os.time())
local j = 0
for i = #t, 2, -1 do
j = math.random(i)
t, t[j] = t[j], t
end
end

[/lua]

table.unpack, to stuningowana wersja table.concat, kt?ra pozwala poda? separator mi?dzy przedostatnim a ostatnim elementem tablicy! Przyk?ad w praktyce:
[lua]
local tbl = {"magic plate armor", "magic longsword", "demon legs"}
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Give me " .. table.unpack(tbl, ', ', ' and ') .. " so I'll give you some shitty item!")[/lua]

Wiadomo??, kt?ra si? wy?wietli graczowi:
Give me magic plate armor, magic longsword and demon legs so I'll give you some shitty item!

Uwaga: je?li chcecie u?ywa? ostatniego separatora, jako wyraz, musicie doda? spacje na pocz?tku i ko?cu dla dobrego wygl?du.

table.merge to zwyk?a funkcja ??cz?ca dwie tabele (po wywo?uaniu funkcji tabela z pierwszego parametru jest tabel? z po??czonymi warto?ciami)

table.shuffle to czasami bardzo przydatna funkcja, kt?ra po prostu losowo miesza kolejno?? warto?ci w tabeli.

Zastosowa? nie b?d? wymienia?, kreatywni skrypterzy powinni widzie? sporo mo?liwo?ci z ich wykorzystania. Enjoy.
 

Oskar

Forum friend
Joined
Jan 24, 2009
Messages
2,256
Reaction score
331
Odp: [LIB] Kilka dodatk?w do 012-table.lua

Ca?kiem ciekawe funkcje. Zastosowa? widz? ca?e mn?stwo, ale sam mam podobne napisane i akurat z Twoich nie skorzystam. Jednak?e co bardziej ambitni skrypterzy by? mo?e (i tutaj podkre?lam - BY? MO?E) b?d? wiedzieli jak z tego korzysta?.
 

Dantez

Moim sekretem jest ciasto
Joined
May 22, 2008
Messages
1,206
Reaction score
202
Odp: [LIB] Kilka dodatk?w do 012-table.lua

Jedyne co mog? doradzi? to zmiana nazwy z unpack na co? innego, poniewa? takowa ju? istnieje.

[LUA]table.unpack (list [, i [, j]])[/LUA]
 

averatec

Active User
Joined
May 19, 2008
Messages
84
Reaction score
4
Odp: [LIB] Kilka dodatk?w do 012-table.lua

proponowa?bym table.concatEx
 

Gandhi

Active User
Joined
Aug 7, 2013
Messages
80
Reaction score
19
Odp: [LIB] Kilka dodatk?w do 012-table.lua

@Oskar

Wcale mnie nie dziwi, ?e masz napisane podobne. : p

@Dantez

Jest taka funkcja, ale z tego co wiem, w LUA 5.2, a ten lib jest g??wnie pod TFS 0.4 / <= 0.3.7, kt?re u?ywaj? LUA 5.1 (no ten ostatni mo?na skompilowa? z 5.2)
 

Dantez

Moim sekretem jest ciasto
Joined
May 22, 2008
Messages
1,206
Reaction score
202
Odp: [LIB] Kilka dodatk?w do 012-table.lua

@Dantez
Jest taka funkcja, ale z tego co wiem, w LUA 5.2, a ten lib jest g??wnie pod TFS 0.4 / <= 0.3.7, kt?re u?ywaj? LUA 5.1 (no ten ostatni mo?na skompilowa? z 5.2)

Nie tyle dodana, co:
table.unpack() and table.pack()
unpack() is renamed to table.unpack(). table.pack() is added, packing arguments to a table and storing number of arguments to table's field "n".

Nie ma przeszkody, ?eby doda? to do TFS 1.0 do pliku global.lua, a zmieniaj?c nazw? uchronimy si? przed nadpisaniem tej ju? ewentualnie istniej?cej.


I jeszcze jedno:
"Lua" (pronounced LOO-ah) means "Moon" in Portuguese. As such, it is neither an acronym nor an abbreviation, but a noun. More specifically, "Lua" is a name, the name of the Earth's moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, "Lua". Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right!
 
Last edited:

sprytnaaaaa

Advanced User
Joined
Apr 20, 2011
Messages
342
Reaction score
4
Odp: [LIB] Kilka dodatk?w do 012-table.lua

Dzi?ki przyda si? 4/10
 

Kahras

Senior User
Joined
Aug 26, 2011
Messages
2,714
Reaction score
167
Age
25
Odp: [LIB] Kilka dodatk?w do 012-table.lua

Dzi?ki przyda si? 4/10

Piszesz by tylko co? napisa? a tak to wgl nie masz poj?cia o co chodzi..


@topic
Og?lnie mi si? chyba nie przyda ale masz + za to !
 
Last edited:
Status
Not open for further replies.
Top