View previous topic :: View next topic |
Author |
Message |
HexaG0n Advanced Cheater Reputation: 0
Joined: 29 Mar 2021 Posts: 64
|
Posted: Sat Jul 17, 2021 1:42 am Post subject: require file in table |
|
|
how can i require a .lua file in the current ce table?
|
|
Back to top |
|
|
LeFiXER Grandmaster Cheater Supreme Reputation: 20
Joined: 02 Sep 2011 Posts: 1055 Location: 0x90
|
Posted: Sat Jul 17, 2021 3:20 am Post subject: |
|
|
Your question doesn't make sense and lacks information.
|
|
Back to top |
|
|
HexaG0n Advanced Cheater Reputation: 0
Joined: 29 Mar 2021 Posts: 64
|
Posted: Sat Jul 17, 2021 4:19 am Post subject: |
|
|
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...
Description: |
|
Filesize: |
11.47 KB |
Viewed: |
2089 Time(s) |
|
|
|
Back to top |
|
|
TheyCallMeTim13 Wiki Contributor Reputation: 50
Joined: 24 Feb 2017 Posts: 976 Location: Pluto
|
Posted: Sat Jul 17, 2021 6:13 am Post subject: |
|
|
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 |
|
|
ByTransient Expert Cheater Reputation: 5
Joined: 05 Sep 2020 Posts: 240
|
Posted: Sat Jul 17, 2021 8:52 am Post subject: |
|
|
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 |
|
|
HexaG0n Advanced Cheater Reputation: 0
Joined: 29 Mar 2021 Posts: 64
|
Posted: Sat Jul 17, 2021 9:40 am Post subject: |
|
|
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 .. 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 |
|
|
ByTransient Expert Cheater Reputation: 5
Joined: 05 Sep 2020 Posts: 240
|
Posted: Sun Jul 18, 2021 11:14 am Post subject: |
|
|
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 |
|
|
|