English MetaLibraries

8 replies
Goto Page
To the start Previous 1 Next To the start
07.05.10 09:19:29 pm
Up
Informatixa
User
Offline Off
MetaLibraries is a project that allows life easier for developers to add their functionality and simple function.

Current Rev: 81
Development Rev: 83

• Download:
     > file cs2d MetaLibraries (4) (r81)

√ Initialize Library

Code:
1
dofile('sys/lua/libraries.luac')


√ Predefined Constants
     _WIN32                          -> Defined for applications for Win32 and Win64
     _WIN64                          -> Defined for applications for Win64
     __LINUX __, __UNIX__     -> Defined for applications for Linux

     BOTSDIR     -> ./bots
     GFXDIR       -> ./gfx
     MAPSDIR     -> ./maps
     SFXDIR       -> ./sfx
     SYSDIR       -> ./sys
     LUADIR       -> ./sys/lua
     SERVERDIR -> The server root directory under which is running

     __FILE__     -> The full path and filename of the file
     __DIR__      -> The directory of the file

     
Code:
1
2
3
4
5
6
7
8
--> ./sys/lua/server.lua
dofile(LUADIR .."/test/init.lua")
print(__FILE__)          -- return ./sys/lua/server.lua
print(__DIR__)           -- return ./sys/lua

--> ./sys/lua/test/init.lua
print(__FILE__)          -- return ./sys/lua/test/init.lua
print(__DIR__)           -- return ./sys/lua/test


Example (Old version r81 and less):
Spoiler >
edited 78×, last 13.12.13 01:16:19 am
IMG:http://img3.imageshack.us/img3/8939/29153.gif
IMG:http://img123.imageshack.us/img123/5111/6152sy7.jpg
Creation of server status image for Counter-Strike 2D (WebSite)
08.05.10 01:24:11 am
Up
Lee
Moderator
Offline Off
The idea is novel, yet the implementation is a bit arcane, you may want to look into simplifying a few method names so that they can easily degrade back to the natural CS2D convention. Besides that, impressive work.

A few annotations on style:
Lua is a nontraditional language, as such it does not normally follow the strict naming conventions of more traditional languages such as Java or the C family. I recommend using a more or less loose hybrid between case-consistency and underscoring for consistency with the rest of the Lua stdlib.

Also, the concept of a pseudo OOP abstraction over Lua is a relatively new one. Make sure that people can adequately differentiate between static and instance methods outside of the arcane declaration of each; the following is an excerpt from player.lua:
Code:
1
2
3
4
5
6
7
8
9
function player.GetBots()
     local Table = {}
     for _, ply in pairs(player.GetAll()) do
          if ply:IsBot() then
               table.insert(Table, ply)
          end
     end
     return Table
end

This is an implicitly static declaration of a GetBots method under the player namespace.
Code:
1
2
3
function meta:UserID()
     return self.ID
end

implictly declares an "instance" method under the Player class. As both are methods under a single common object type (a pseudo class if you will), it is more rational to group both within the same namespace. (This should be easily achievable as your objects are already designed this way.)

On another note, it is usually not a good idea to litter temporary variables names throughout your global namespace without explicit cleanup after initiation.
09.05.10 10:51:57 pm
Up
YellowBanana
BANNED
Offline Off
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
function player.GetAll()
     local Table = {}
     for _, v in pairs(_player(0, "table")) do
          table.insert(Table, player.GetByID(v))
     end
     return Table     
end

-->

function player.GetAll()
     return _player(0,"table")
end


It seems like you're just copying a table.
player(0,"table") returns only existing players.
10.05.10 01:55:37 am
Up
Lee
Moderator
Offline Off
YellowBanana has written:
It seems like you're just copying a table.

Not exactly, the table encloses a set of "instances" of his player class. But you are definitely on to something.

The danger lies in the static method
Code:
1
2
3
4
5
6
function player.GetByID(id)
     if id == 0 or not tobool(_player(id, "exists")) then return nil end
     local Table = meta
     Table.ID = id
     return Table
end


Which, due to the way that Lua passes references, will in turn render 'meta' into a static class. I'll illustrate this problem with the following example:

Code:
1
2
3
4
obj = {id=3}
proxy = obj
proxy.id = 4
assert(proxy.id ~= obj.id)


The above code will raise an assertion error because obj.id now becomes 4. The object references are passed along with the variable name so that in the above environment, the following state will actually be true:

Code:
1
assert(proxy == obj)


because you see, the reference 'proxy' and the reference 'obj' points to the same object (Think of this as borrowing references instead of owning them, something that's relatively common in all C-derived paradigms).
14.11.11 02:53:58 am
Up
Informatixa
User
Offline Off
> New revision available r77
IMG:http://img3.imageshack.us/img3/8939/29153.gif
IMG:http://img123.imageshack.us/img123/5111/6152sy7.jpg
Creation of server status image for Counter-Strike 2D (WebSite)
14.11.11 06:31:54 am
Up
Apache uwu
User
Offline Off
Oh thought it was Metal Libraries

Code:
1
2
3
hook.Add("join", "Welcom", function(ply)
     ply:PrintMessage(HUD_PRINTCENTER, "©000128128Welcom to my server.")
end)


Looks awesome, so...potentially using:

Code:
1
Welcom(1)


it should msg them?
14.11.11 05:45:07 pm
Up
Informatixa
User
Offline Off
user Apache uwu has written:
Oh thought it was Metal Libraries

Code:
1
2
3
hook.Add("join", "Welcom", function(ply)
     ply:PrintMessage(HUD_PRINTCENTER, "©000128128Welcom to my server.")
end)


Looks awesome, so...potentially using:

Code:
1
Welcom(1)


it should msg them?


No name is to identify when you want to remove a hook
Code:
1
hook.Remove("join", "Welcom")


but otherwise to recover the function
Code:
1
2
3
4
5
6
7
function Welcom(ply)
     ply:PrintMessage(HUD_PRINTCENTER, "©000128128Welcom to my server.")
end
hook.Add("join", "Welcom", Welcom)


Welcom(player.GetByID(1))


Sorry for my bad English
IMG:http://img3.imageshack.us/img3/8939/29153.gif
IMG:http://img123.imageshack.us/img123/5111/6152sy7.jpg
Creation of server status image for Counter-Strike 2D (WebSite)
14.11.11 09:47:45 pm
Up
Apache uwu
User
Offline Off
Oh cool, if this were on the file archive I would like it

I skimmed over some of the files--lots of finals !!
14.11.11 11:21:24 pm
Up
Informatixa
User
Offline Off
Added to file archive

file cs2d MetaLibraries (4)
IMG:http://img3.imageshack.us/img3/8939/29153.gif
IMG:http://img123.imageshack.us/img123/5111/6152sy7.jpg
Creation of server status image for Counter-Strike 2D (WebSite)
To the start Previous 1 Next To the start