Hi all
Seems like the "include" directive cannot find my Lua file:
RequireOnceDB: Loaded from: ../trackassembly/db_PIECES.lua
Couldn't include file '..\trackassembly\db_pieces.lua' (File not found) (@addons/trackassembly/lua/includes/modules/assemblylib.lua
It says in the doc absolute path, so:
My module is located in: "\addons\TrackAssembly\lua\includes\modules"
The *.lua sources are in: "\addons\TrackAssembly\lua\includes\trackassembly" <--- Have to include this in case a file is missing
Inside my module I got the following function:
[code]
function RequireOnceDB(sTable,sDelim)
if(not sTable or type(sTable) ~= "string") then return false end
if(not sDelim or type(sDelim) ~= "string") then return false end
print("RequireOnceDB Params OK !")
print("RequireOnceDB Table OK !")
if(file.Exists(AssemblyLib.BASPath..
AssemblyLib.DSVPath..
"db_"..sTable..".txt", "DATA") -- = "data\trackassembly\dsvbase\db_"..sTable
) then
print("RequireOnceDB: Retrived from: "..
AssemblyLib.BASPath..
AssemblyLib.DSVPath..
"db_"..sTable..".txt") -- Print path
else
print("RequireOnceDB: Loaded from: ../"..AssemblyLib.BASPath.."db_"..sTable..".lua")
include( "../"..AssemblyLib.BASPath.."db_"..sTable..".lua" )
end
return true
end
[/code]
Basic Program Log
[code]
addons/trackassembly/lua/includes/db_pieces.lua
Couldn't include file 'addons\trackassembly\lua\includes\trackassembly\db_pieces' (File not found) (@addons/trackassembly/lua/includes/modules/assemblylib.lua (line 2190))
RequireOnceDB: PI true
RequireOnceDB Params OK !
RequireOnceDB Table OK !
addons/trackassembly/lua/includes/db_additions.lua
Couldn't include file 'addons\trackassembly\lua\includes\trackassembly\db_additions' (File not found) (@addons/trackassembly/lua/includes/modules/assemblylib.lua (line 2190))
RequireOnceDB: AD true
RequireOnceDB Params OK !
RequireOnceDB Table OK !
addons/trackassembly/lua/includes/db_physproperties.lua
Couldn't include file 'addons\trackassembly\lua\includes\trackassembly\db_physproperties' (File not found) (@addons/trackassembly/lua/includes/modules/assemblylib.lua (line 2190))
RequireOnceDB: PH true
[/code]
It does not work even if I give it like follows:
addons\trackassembly\lua\includes\trackassembly\db_physproperties.lua
lua\includes\trackassembly\db_physproperties.lua
..\trackassembly\db_physproperties.lua
So how can I do that ... 10x forum !
Looks like you have one too many directory jump-ups in the call to include.
"../../"
[QUOTE=Willox;46685222]Looks like you have one too many directory jump-ups in the call to include.
"../../"[/QUOTE]
Yep that is the second thing I tried ... after putting a "../" ( Which does not work ether ... )
Use global paths: includes/modules/assemblylib.lua
[QUOTE=Robotboy655;46685427]Use global paths: includes/modules/assemblylib.lua[/QUOTE]
Did you mean: addons/trackassembly/includes/trackassembly/db_pieces.lua ??
Module is loaded perfectly ( By just calling require ( "assemblylib" ) from the tool ) , but can't seem to include and execute:
[code] ( addons\trackassembly\ ) "includes\trackassembly\db_pieces.lua" [/code]
Already tried: include( sPath ), where "sPath" is one of the following, executing directly when the tool is loaded ( The function is called from the tool script, and its definition persists in the module ) :
[code]
assemblylib.RequireOnceDB("PIECES")
"addons/trackassembly/includes/trackassembly/db_pieces.lua" ( Full path )
"includes/trackassembly/db_pieces.lua" ( Includes relative )
../includes/trackassembly/db_pieces.lua" ( Module Relative )
[/code]
This also failed ....
[code]
include( "lua/includes/trackassembly/pieces_db.lua" )
include( "lua/includes/trackassembly/additions_db.lua" )
include( "lua/includes/trackassembly/physproperties_db.lua" )
[/code]
-snip-
Didn't they remove .. and . support to prevent "break-outs"?
[QUOTE=Acecool;46691095]Didn't they remove .. and . support to prevent "break-outs"?[/QUOTE]
Nope, still works for me, try make a file in data called lol.txt with a print in it then run
[lua]include( "../data/lol.txt" )[/lua]
and it will run fine
[QUOTE=ZombieWizzard;46691773]Nope, still works for me, try make a file in data called lol.txt with a print in it then run
[lua]include( "../data/lol.txt" )[/lua]
and it will run fine[/QUOTE]
Yep it works that way, but you see I cantt ship *.txt files using Garry's gmad convetror and publisher...
Tried the following code and it works perfectly fine using the non-gmod Lua..
E:\Documents\Lua\Lua\lua-gmod\tool.lua
[code]
require("includes/modules/sum")
local D = sum.Summer(10,15)
print("Main: "..D:DoIt())
[/code]
E:\Documents\Lua\Lua\lua-gmod\includes\modules\sum.lua
[code]
local pairs = pairs
local type = type
local tostring = tostring
local tonumber = tonumber
local print = print
local include = include
local require = require
local package = package
local Log = print
module("sum",package.seeall)
function Summer(a,b)
local a = a or 0
local b = b or 0
self = {}
function self:DoIt()
return a + b
end
return self
end
A = Summer(1,2)
print("Modu: "..A:DoIt())
require("includes/trackassembly/data-a")
require("includes/trackassembly/data-b")
[/code]
E:\Documents\Lua\Lua\lua-gmod\includes\trackassembly\data-a.lua
[code]
-- Make a "Summer object to simulate sql.Query() insert"
local aB = sum.Summer(3,4)
local aC = sum.Summer(5,6)
print("Data A: "..aB:DoIt())
print("Data A: "..aC:DoIt())
[/code]
E:\Documents\Lua\Lua\lua-gmod\includes\trackassembly\data-b.lua
[code]
-- Make a "Summer object to simulate sql.Query() insert"
local bB = sum.Summer(3,4)
local bC = sum.Summer(5,6)
print("Data B: "..bB:DoIt())
print("Data B: "..bC:DoIt())
[/code]
Running this ( "E:\Documents\Lua\Lua\lua-gmod>..\Bin\lua.exe tool.lua" --> my lua.exe is located in "Lua\Bin"), I am getting the following output:
[code]
-- Loading module
Modu: 3 -- Call and exec the module
-- Load the data trough the module
Data A: 7 -- Load data from A
Data A: 11 -- Load data from A
Data B: 7 -- Load data from B
Data B: 11 -- Load data from B
-- Finish the job in the main file
Main: 25 -- Execute "D" object
[/code]
[editline]12th December 2014[/editline]
You see, the thing is that I wanna execute the inserts of my database in a separate files, so it wont stay inside the script of the tool and also is a file is present in the data folder read the contents from it, else load the Lua INSERT-s from the addons folder...
[editline]12th December 2014[/editline]
the tool and also * IF * a file ( Sorry facepunch is not letting me edit this thing ...)
[editline]12th December 2014[/editline]
but you see I can * ' * t ship *.txt files ( Another one )
Instead of shipping a txt file, ship a Lua file that checks the CRC of the txt file ( if it exists ) against the CRC of what the contents should be. If the CRC doesn't match, or the file doesn't exist, create it and populate the data.
Here's an example of what I do if people want the full folder-structure for my dev-base: [url]https://bitbucket.org/Acecool/acecooldev_base/src/master/gamemode/addons/_development/sv_setup_folders.lua?at=master[/url]
I don't do it automatically ( creating the folders in the data folder ) because they may not like how I organize the folders or they may not want empty folders... BUT, this can easily be applied to txt files that should be included.
Sorry, you need to Log In to post a reply to this thread.