[Orxonox-commit 1909] r6626 - in code/branches/gamestate: data/lua src/libraries/core
rgrieder at orxonox.net
rgrieder at orxonox.net
Sun Mar 28 19:16:12 CEST 2010
Author: rgrieder
Date: 2010-03-28 19:16:12 +0200 (Sun, 28 Mar 2010)
New Revision: 6626
Modified:
code/branches/gamestate/data/lua/Debugger.lua
code/branches/gamestate/src/libraries/core/LuaState.cc
code/branches/gamestate/src/libraries/core/LuaState.h
Log:
Modified Debugger.lua so we can debug any Lua files from our Resources.
Debugging strings loaded with loadstring() cannot be debugged (not supported by Debugger.lua, it always assumes files).
Modified: code/branches/gamestate/data/lua/Debugger.lua
===================================================================
--- code/branches/gamestate/data/lua/Debugger.lua 2010-03-28 13:21:44 UTC (rev 6625)
+++ code/branches/gamestate/data/lua/Debugger.lua 2010-03-28 17:16:12 UTC (rev 6626)
@@ -1,6 +1,7 @@
--{{{ history
+--28/03/10 ORX Adjusted show() to work with the Orxonox resource system
--15/03/06 DCN Created based on RemDebug
--28/04/06 DCN Update for Lua 5.1
--01/06/06 DCN Fix command argument parsing
@@ -395,46 +396,60 @@
before = tonumber(before or 10)
after = tonumber(after or before)
- if not string.find(file,'%.') then file = file..'.lua' end
+ -- Try to find the file in the Orxonox resources
+ local text = luaState:getSourceCode(file)
- local f = io.open(file,'r')
- if not f then
- --{{{ try to find the file in the path
+ if text == "" then
+ if not string.find(file,'%.') then file = file..'.lua' end
+
+ local f = io.open(file,'r')
+ if not f then
+ --{{{ try to find the file in the path
- --
- -- looks for a file in the package path
- --
- local path = package.path or LUA_PATH or ''
- for c in string.gmatch (path, "[^;]+") do
- local c = string.gsub (c, "%?%.lua", file)
- f = io.open (c,'r')
+ --
+ -- looks for a file in the package path
+ --
+ local path = package.path or LUA_PATH or ''
+ for c in string.gmatch (path, "[^;]+") do
+ local c = string.gsub (c, "%?%.lua", file)
+ f = io.open (c,'r')
+ if f then
+ break
+ end
+ end
+
+ --}}}
+
if f then
- break
+ -- Read file into 'text'
+ text = f:read("*a")
+ f:close()
+ else
+ io.write('Cannot find '..file..'\n')
+ return
end
end
-
- --}}}
- if not f then
- io.write('Cannot find '..file..'\n')
- return
- end
end
+ -- Transform line endings to \n
+ text :gsub("\r\n", "\n") -- Windows to Unix
+ text:gsub("\r", "\n") -- Mac to Unix
+ if text[-1] ~= "\n" then
+ text = text.."\n"
+ end
+ -- Print requested lines
local i = 0
- for l in f:lines() do
+ for l in text:gmatch("[^\n]*[\n]") do
i = i + 1
if i >= (line-before) then
if i > (line+after) then break end
if i == line then
- io.write(i..'***\t'..l..'\n')
+ io.write(i..'***\t'..l)
else
- io.write(i..'\t'..l..'\n')
+ io.write(i..'\t'..l)
end
end
end
-
- f:close()
-
end
--}}}
@@ -610,7 +625,8 @@
if string.find(file, "@") == 1 then
file = string.sub(file, 2)
end
- if IsWindows then file = string.lower(file) end
+ -- Orxonox changes: Our resource system is case sensisive, even on Windows
+ --if IsWindows then file = string.lower(file) end
if not line then
line = getinfo(lvl, "currentline")
Modified: code/branches/gamestate/src/libraries/core/LuaState.cc
===================================================================
--- code/branches/gamestate/src/libraries/core/LuaState.cc 2010-03-28 13:21:44 UTC (rev 6625)
+++ code/branches/gamestate/src/libraries/core/LuaState.cc 2010-03-28 17:16:12 UTC (rev 6626)
@@ -134,16 +134,16 @@
sourceFileInfo_ = sourceFileInfo;
std::string chunkname;
- if (sourceFileInfo != NULL && !sourceFileInfo->fileSystemPath.empty())
+ if (sourceFileInfo != NULL)
{
// Provide lua_load with the filename for debug purposes
// The '@' is a Lua convention to identify the chunk name as filename
- chunkname = '@' + sourceFileInfo->fileSystemPath;
+ chunkname = '@' + sourceFileInfo->filename;
}
else
{
- // Use the beginning of the code string to identify the chunk
- chunkname = code.substr(0, 80);
+ // Use the code string to identify the chunk
+ chunkname = code;
}
int error = 0;
@@ -194,6 +194,16 @@
return true;
}
+ //! Returns the content of a file
+ std::string LuaState::getSourceCode(const std::string& filename)
+ {
+ shared_ptr<ResourceInfo> info = Resource::getInfo(filename);
+ if (info == NULL)
+ return "";
+ else
+ return Resource::open(info)->getAsString();
+ }
+
#if LUA_VERSION_NUM != 501
const char * LuaState::lua_Chunkreader(lua_State *L, void *data, size_t *size)
{
Modified: code/branches/gamestate/src/libraries/core/LuaState.h
===================================================================
--- code/branches/gamestate/src/libraries/core/LuaState.h 2010-03-28 13:21:44 UTC (rev 6625)
+++ code/branches/gamestate/src/libraries/core/LuaState.h 2010-03-28 17:16:12 UTC (rev 6626)
@@ -79,6 +79,7 @@
void luaPrint(const std::string& str); // tolua_export
void luaLog(unsigned int level, const std::string& message); // tolua_export
bool fileExists(const std::string& filename); // tolua_export
+ std::string getSourceCode(const std::string& filename); // tolua_export
const std::stringstream& getOutput() const { return output_; }
void clearOutput() { output_.clear(); } // tolua_export
More information about the Orxonox-commit
mailing list