Forum

> > CS2D > Scripts > New dofile system
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch New dofile system

10 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt New dofile system

MikuAuahDark
User Off Offline

Zitieren
this is a new dofile system which ignore the file when it's not exists or errors

System:
this new system will check file directory from dofile(bot lua too). it will check:
• ∗ > hooks(and how much hooks)
• ∗ > lines
• ∗ > file(when file is existsold system)
• ∗ > filesize(in byte)
• ∗ > few correct files(if there is a files not found, scan only on sys/lua folders)

Known Bugs:
No bugs known

Logs >


How to install:
Put the code(below) on server.lua
Put the code before any "dofile"

Code >

N.B.: It was tested!

How it works?
• ∗ > hooks(and how much hooks):
use a string.gmatch to loop and table.insert to put the string on table
• ∗ > lines
use io.lines and use fileline+1
• ∗ > file(when file is exists(old system))
i use my custom function(io.exists)
• ∗ > filesize(in byte)
i use my custom function(io.size)
• ∗ > few correct files
i use my custom function(string.match and string.table)

Note:
• When the dofile code is updated, i will make this thread is unread thread!
• Not work on Linux(it has os.execute with windows commands)
5× editiert, zuletzt 28.01.13 13:49:44

alt Re: New dofile system

VADemon
User Off Offline

Zitieren
Good thought. But in fact when one or more files wouldn't load such scripts like SuperHero won't work at all.

This is useful only for small, one-file scripts and lazy (and stupid) admins
1× editiert, zuletzt 28.01.13 15:57:38

alt Re: New dofile system

TimeQuesT
User Off Offline

Zitieren
You should return a boolean.
False if the file is unable to load and true if it is.

So there are more possibilitys.
like:

1
2
3
4
5
if (dofile("Test")) then
--code here
else
exit(-1);
end

alt Re: New dofile system

Apache uwu
User Off Offline

Zitieren
You should use pcall, so if it fails in either syntax or in general it will return an error.

Kinda like try & catch in most languages.

Usually you would require a file that you know exists. Unless you have a variable name.

alt Re: New dofile system

MostAfa
User Off Offline

Zitieren
Just a question. Is your Code does the same thing as this code?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
--DOFILES LIST--
local dofiles={
	"/home/TLex/Locmod/luafilename.lua",
	"sys/lua/Luas/luafilename.lua",
	"/home/TLex/luafilename.lua",
	}

--LOAD DOFILES--
function load_dofiles()
	for i=1,#dofiles do
		local f=loadfile(dofiles[i])
		if not f then
			print("***************************************")
			print("Dofiles.lua Error: Could not load script: "..dofiles[i])
			print("***************************************")
		else
			f()
		end
	end
end

--BEGIN LOADING--
load_dofiles()

Just checking, anyone is welcomed to use that Lua I pasted. It works. Just edit the dofiles directories.

alt Re: New dofile system

MostAfa
User Off Offline

Zitieren
user MikuAuahDark hat geschrieben
@user MostAfa: no, my script is simple, and to use it just use dofile normally, not like your script!
EDIT: how to make LUA read "dofile(bla)"? i need it for improving dofile system(when error detected in some script, it will continue loading another script)


That's exactly what my Lua does. Just dofile it here..

1
2
3
4
5
local dofiles={
     "/home/TLex/Locmod/luafilename.lua",
     "sys/lua/Luas/luafilename.lua",
     "/home/TLex/luafilename.lua",
     }

alt Re: New dofile system

Apache uwu
User Off Offline

Zitieren
It is true that dofile is faster, however loadfile is like a try catch for lua.

     Though I agree, if one script fails you should stop any others from processing, it would be catastrophic if people could bypass usgn detection but still have the ability to use commands.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht