Forum

> > CS2D > Scripts > New dofile system
Forums overviewCS2D overview Scripts overviewLog in to reply

English New dofile system

10 replies
To the start Previous 1 Next To the start

old New dofile system

MikuAuahDark
User Off Offline

Quote
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)
edited 5×, last 28.01.13 01:49:44 pm

old Re: New dofile system

VADemon
User Off Offline

Quote
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
edited 1×, last 28.01.13 03:57:38 pm

old Re: New dofile system

TimeQuesT
User Off Offline

Quote
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

old Re: New dofile system

Apache uwu
User Off Offline

Quote
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.

old Re: New dofile system

MostAfa
User Off Offline

Quote
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.

old Re: New dofile system

MostAfa
User Off Offline

Quote
user MikuAuahDark has written
@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",
     }

old Re: New dofile system

Apache uwu
User Off Offline

Quote
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.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview