Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


require file in table

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
HexaG0n
Advanced Cheater
Reputation: 0

Joined: 29 Mar 2021
Posts: 64

PostPosted: Sat Jul 17, 2021 1:42 am    Post subject: require file in table Reply with quote

how can i require a .lua file in the current ce table?
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1055
Location: 0x90

PostPosted: Sat Jul 17, 2021 3:20 am    Post subject: Reply with quote

Your question doesn't make sense and lacks information.
Back to top
View user's profile Send private message
HexaG0n
Advanced Cheater
Reputation: 0

Joined: 29 Mar 2021
Posts: 64

PostPosted: Sat Jul 17, 2021 4:19 am    Post subject: Reply with quote

i want to require a .lua file in the cetable, is it possible?

i want to require numsy.lua so i can use the functions in it...



req.PNG
 Description:
 Filesize:  11.47 KB
 Viewed:  2086 Time(s)

req.PNG


Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Sat Jul 17, 2021 6:13 am    Post subject: Reply with quote

I use this to require table files.
Code:
--------
-------- CE Table Require
--------
local tableLuaFilesDirectory = 'luaFiles'
local fileExt = '.lua'
function CETrequire(moduleStr)
   if moduleStr ~= nil then
      local localTableLuaFilePath = moduleStr
      if tableLuaFilesDirectory ~= nil and tableLuaFilesDirectory ~= '' then
         local sep = package.config:sub(1,1)
         localTableLuaFilePath = tableLuaFilesDirectory .. sep .. moduleStr
      end
      local f, err = io.open(localTableLuaFilePath .. fileExt)
      if f and not err then
         f:close()
         return dofile(localTableLuaFilePath .. fileExt)
      else
         local tableFile = findTableFile(moduleStr .. fileExt)
         if tableFile == nil then
            return nil
         end
         local stream = tableFile.getData()
         local fileStr = nil
         local bytes = stream.read(stream.Size)
         for i = 1, #bytes do
            if fileStr == nil then
               fileStr = ''
            end
            fileStr = fileStr .. string.char(bytes[i])
         end
         if fileStr then
            return loadstring(fileStr)()
         end
      end
   end
   return nil
end
-- CETrequire('I2CETableCEA')
-- CETrequire('SomeLuaModuleStoredAsTableFile')
-- SomeLuaModuleStoredAsTableFile.printTest() -- Just an example.


So you can use the table files directly, and override with files in a "luaFiles" folder for updating/testing. Just put this in the table Lua script.

_________________
Back to top
View user's profile Send private message Visit poster's website
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Sat Jul 17, 2021 8:52 am    Post subject: Reply with quote

A little shorter and tested.

Code:
--[[--numsy.lua content:
function colors()
return 0xFFFF00
end

function desc()
return "This description: Installed from the Lua supplement!"
end
]]

local lua1 = findTableFile('numsy.lua').stream;
lua1 = load(readStringLocal(lua1.memory,lua1.size))()

form1=createForm()
form1.Width=600
form1.color=colors()
form1.caption=desc()


Use @TheyCallMeTim13's code for a working and installable ".lua" test.
Back to top
View user's profile Send private message
HexaG0n
Advanced Cheater
Reputation: 0

Joined: 29 Mar 2021
Posts: 64

PostPosted: Sat Jul 17, 2021 9:40 am    Post subject: Reply with quote

ByTransient wrote:
A little shorter and tested.

Code:
--[[--numsy.lua content:
function colors()
return 0xFFFF00
end

function desc()
return "This description: Installed from the Lua supplement!"
end
]]

local lua1 = findTableFile('numsy.lua').stream;
lua1 = load(readStringLocal(lua1.memory,lua1.size))()

form1=createForm()
form1.Width=600
form1.color=colors()
form1.caption=desc()


Use @TheyCallMeTim13's code for a working and installable ".lua" test.


thank you so much! this works for me Very Happy.. i made a function for it

Code:
function CETreq(modulename)
if findTableFile(modulename) ~= nil then
local lua1 = findTableFile(modulename).stream;
load(readStringLocal(lua1.memory, lua1.size))()
else
return "Module not found in table!"
end
end

print(CETreq('numsy.lua'))
print(str2dec('hello'))
Back to top
View user's profile Send private message
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Sun Jul 18, 2021 11:14 am    Post subject: Reply with quote

If you are going to test, two issues are important;

1) Is the file available?
2) Is the file an executable?
The following example worked for two tests.

Code:
--[[--numsy.lua content:
function colors()
return 0xFFFF00
end

function desc()
return "This description: Installed from the Lua supplement!"
end
]]
--[[--numsy1.lua content:
aaaaaaaa
]]

function reguire(files)
lua1 = findTableFile(files).stream;
--Is the file available?
if lua1~=nil then
--Is the file an executable?
lua2 = loadstring(readStringLocal(lua1.memory,lua1.size)) --for testing
if lua2~=nil then
load(readStringLocal(lua1.memory,lua1.size))() --success
else
showMessage("Error!\n"..files.."\n not an executable file.") --error
return false end
else
showMessage("File does not exist!")
end
end

reguire('numsy1.lua')
reguire('numsy.lua')

form1=createForm()
form1.Width=600
form1.color=colors()
form1.caption=desc()
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites