fix bug on how lua detect source paths

master
Eduardo Bart 13 years ago
parent 80e42b0f96
commit f5a15939b2

@ -1,34 +1,34 @@
window#enterGameWindow:
window#enterGameWindow
title: Enter Game
size: [236, 178]
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
onLoad: self.locked = true
label#accountNameLabel:
label#accountNameLabel
text: Account name
anchors.left: parent.left
anchors.top: parent.top
margin.left: 18
margin.top: 33
label#passwordLabel:
label#passwordLabel
text: "Password:"
anchors.left: parent.left
anchors.top: parent.top
margin.left: 18
margin.top: 62
label#createAccountLabel:
label#createAccountLabel
text: |
If you don't have
an account yet
If you don't have
an account yet
anchors.left: parent.left
anchors.top: parent.top
margin.left: 18
margin.top: 87
button#createAccountButton:
button#createAccountButton
text: Create Account
anchors.left: parent.left
anchors.top: parent.top
@ -36,7 +36,7 @@ window#enterGameWindow:
margin.left: 132
onClick: messageBox("Error", "Not implemented yet")
button#okButton:
button#okButton
text: Ok
size: [43, 20]
anchors.right: parent.right
@ -44,7 +44,7 @@ window#enterGameWindow:
margin.bottom: 10
margin.right: 66
button#cancelButton:
button#cancelButton
text: Cancel
size: [43, 20]
anchors.right: parent.right
@ -53,13 +53,13 @@ window#enterGameWindow:
margin.right: 13
onClick: self.parent:destroy()
textEdit#accountNameTextEdit:
textEdit#accountNameTextEdit
anchors.right: parent.right
anchors.top: parent.top
margin.top: 32
margin.right: 18
textEdit#passwordTextEdit:
textEdit#passwordTextEdit
anchors.right: parent.right
anchors.top: parent.top
margin.top: 61

@ -1,11 +1,11 @@
window#infoWindow:
window#infoWindow
title: Info
size: [244, 221]
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
onLoad: self.locked = true
panel#infoPanel:
panel#infoPanel
skin: flatPanel
size: [208, 129]
anchors.left: parent.left
@ -13,31 +13,31 @@ window#infoWindow:
margin.top: 32
margin.left: 18
label#infoLabel:
label#infoLabel
align: center
text: |-
OTClient
Version 0.2.0
Created by edubart
OTClient
Version 0.2.0
Created by edubart
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
margin.top: 20
lineDecoration#bottomSeparator:
size: [190,2]
lineDecoration#bottomSeparator
size: [190, 2]
anchors.left: parent.left
anchors.top: parent.top
margin.top: 83
margin.left: 9
label#websiteLabel:
label#websiteLabel
text: Official Website
anchors.left: parent.left
anchors.bottom: parent.bottom
margin.bottom: 14
margin.left: 9
button#websiteButton:
button#websiteButton
text: Github Page
size: [80,22]
anchors.right: parent.right
@ -45,7 +45,7 @@ window#infoWindow:
margin.bottom: 9
margin.right: 9
lineDecoration#bottomSeparator:
lineDecoration#bottomSeparator
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
@ -53,7 +53,7 @@ window#infoWindow:
margin.left: 13
margin.right: 13
button#okButton:
button#okButton
text: Ok
size: [43, 20]
anchors.left: parent.left

@ -1,11 +1,11 @@
panel#background:
panel#background
skin: mainMenuBackground
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
panel#icos4d:
panel#icos4d
skin:
image: /skins/lightness/mouse.png
anchors.left: parent.left
@ -13,7 +13,7 @@ panel#background:
margin.left: -2
margin.top: 70
panel#mouse:
panel#mouse
skin:
image: /skins/lightness/icos4d.png
anchors.right: parent.right
@ -21,7 +21,7 @@ panel#background:
margin.left: 60
margin.top: 70
panel#mainMenu:
panel#mainMenu
skin: roundedGridPanel
size: [117, 171]
anchors.left: parent.left
@ -29,35 +29,35 @@ panel#background:
margin.left: 60
margin.bottom: 70
button#enterGameButton:
button#enterGameButton
text: Enter Game
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
margin.top: 16
onClick: UI.load("entergamewindow.yml")
button#accessAccountButton:
button#accessAccountButton
text: Access Account
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
margin.top: 46
onClick: messageBox("Error", "Not implemented yet")
button#optionsButton:
button#optionsButton
text: Options
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
margin.top: 76
onClick: UI.load("optionswindow.yml")
button#infoButton:
button#infoButton
text: Info
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
margin.top: 106
onClick: UI.load("infowindow.yml")
button#exitGameButton:
button#exitGameButton
text: Exit
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter

@ -1,4 +1,4 @@
window#optionsWindow:
window#optionsWindow
title: Options
size: [286, 262]
anchors.horizontalCenter: parent.horizontalCenter
@ -6,48 +6,48 @@ window#optionsWindow:
onLoad: self.locked = true
# general
button#generalButton:
button#generalButton
text: General
anchors.left: parent.left
anchors.top: parent.top
margin.left: 18
margin.top: 32
label#generalLabel:
label#generalLabel
text: |-
Change general
game options
Change general
game options
anchors.left: parent.left
anchors.top: parent.top
margin.left: 117
margin.top: 29
# graphics
button#graphicsButton:
button#graphicsButton
text: Graphics
anchors.left: parent.left
anchors.top: parent.top
margin.left: 18
margin.top: 65
label#graphicsLabel:
label#graphicsLabel
text: |-
Change graphics and
performance settings
Change graphics and
performance settings
anchors.left: parent.left
anchors.top: parent.top
margin.left: 117
margin.top: 62
# console
button#consoleButton:
button#consoleButton
text: Console
anchors.left: parent.left
anchors.top: parent.top
margin.left: 18
margin.top: 98
label#consoleLabel:
label#consoleLabel
text: Customise the console
anchors.left: parent.left
anchors.top: parent.top
@ -55,21 +55,21 @@ window#optionsWindow:
margin.top: 95
# hotkeys
button#hotkeysButton:
button#hotkeysButton
text: Hotkeys
anchors.left: parent.left
anchors.top: parent.top
margin.left: 18
margin.top: 131
label#hotkeysLabel:
label#hotkeysLabel
text: Edit your hotkey texts
anchors.left: parent.left
anchors.top: parent.top
margin.left: 117
margin.top: 128
lineDecoration#middleSeparator:
lineDecoration#middleSeparator
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
@ -78,23 +78,23 @@ window#optionsWindow:
margin.right: 18
# motd
button#motdButton:
button#motdButton
text: Motd
anchors.left: parent.left
anchors.bottom: parent.bottom
margin.left: 18
margin.bottom: 60
label#motdLabel:
label#motdLabel
text: |-
Show the most recent
Message of the Day
Show the most recent
Message of the Day
anchors.left: parent.left
anchors.bottom: parent.bottom
margin.left: 117
margin.bottom: 56
lineDecoration#bottomSeparator:
lineDecoration#bottomSeparator
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
@ -103,7 +103,7 @@ window#optionsWindow:
margin.right: 13
# ok button
button#okButton:
button#okButton
text: Ok
size: [43, 20]
anchors.right: parent.right

@ -7,5 +7,5 @@ function messageBox(title, text)
msgBox.locked = true
msgBox.title = title
msgBox:child("textLabel").text = text
msgBox:child("okButton").onClick = autoDestroyParentz
msgBox:child("okButton").onClick = autoDestroyParent
end

@ -105,10 +105,11 @@ bool Resources::directoryExists(const std::string& directoryName)
bool Resources::loadFile(const std::string& fileName, std::iostream& out)
{
std::string fullPath = resolvePath(fileName);
out.clear(std::ios::goodbit);
PHYSFS_file *file = PHYSFS_openRead(resolvePath(fileName).c_str());
PHYSFS_file *file = PHYSFS_openRead(fullPath.c_str());
if(!file) {
flogError("ERROR: Failed to load file \"%s\": %s", fileName.c_str() % PHYSFS_getLastError());
flogError("ERROR: Failed to load file \"%s\": %s", fullPath.c_str() % PHYSFS_getLastError());
out.clear(std::ios::failbit);
return false;
} else {

@ -379,20 +379,25 @@ void LuaScript::pushRef(int ref)
lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
}
std::string LuaScript::getFunctionSourcePath()
std::string LuaScript::getFunctionSourcePath(bool functionIsOnStack, int level)
{
std::string path;
lua_Debug ar;
memset(&ar, 0, sizeof(ar));
lua_getinfo(L, ">Sn", &ar);
if(functionIsOnStack)
lua_getinfo(L, ">Sn", &ar);
else {
if(lua_getstack(L, level-1, &ar) == 1)
lua_getinfo(L, "Sn", &ar);
}
// c function, we must get information of level above
// c function, we must get information of a level above
if(strcmp("C", ar.what) == 0) {
memset(&ar, 0, sizeof(ar));
if(lua_getstack(L, 1, &ar) == 1) {
if(lua_getstack(L, level, &ar) == 1) {
lua_getinfo(L, "f", &ar);
return getFunctionSourcePath();
return getFunctionSourcePath(true, level+1);
}
} else {
@ -411,7 +416,7 @@ std::string LuaScript::getFunctionSourcePath()
bool LuaScript::callFunction(int numArgs, int numRets)
{
pushValue(-numArgs - 1);
g_resources.pushCurrentPath(getFunctionSourcePath());
g_resources.pushCurrentPath(getFunctionSourcePath(true));
int size = getStackSize();
int errorIndex = -numArgs - 2;
@ -726,8 +731,14 @@ int LuaScript::luaFunctionCallback(lua_State* L)
{
// look for function id
int id = lua_tonumber(L, lua_upvalueindex(1));
g_resources.pushCurrentPath(g_lua.getFunctionSourcePath(false));
// call the function
return (*(g_lua.m_functions[id]))();
int ret = (*(g_lua.m_functions[id]))();
g_resources.popCurrentPath();
return ret;
}
int LuaScript::luaErrorHandler(lua_State *L)

@ -104,7 +104,7 @@ public:
void pushValue(int index = -1);
void pushRef(int ref);
std::string getFunctionSourcePath();
std::string getFunctionSourcePath(bool functionIsOnStack, int level = 1);
bool callFunction(int numArgs = 0, int numRets = 0);
void callModuleField(const std::string& module, const std::string& field);

@ -71,7 +71,7 @@ UIElementPtr UILoader::loadFromFile(std::string filePath, const UIContainerPtr&
{
std::stringstream fin;
if(!g_resources.loadFile(filePath, fin)) {
flogError("ERROR: Could not load ui file \"%s", filePath.c_str());
flogError("ERROR: Could not load ui %s", filePath.c_str());
return UIElementPtr();
}
@ -106,7 +106,7 @@ UIElementPtr UILoader::loadFromFile(std::string filePath, const UIContainerPtr&
element->onLoad();
return element;
} else {
flogError("ERROR: Failed to load ui file \"%s\":\n %s", filePath.c_str() % parser.getErrorMessage());
flogError("ERROR: Failed to load ui %s: %s", filePath.c_str() % parser.getErrorMessage());
}
return UIElementPtr();

Loading…
Cancel
Save