From commitmsg at worldforge.de Sun Jun 1 05:59:20 2008 From: commitmsg at worldforge.de (commitmsg at worldforge.de) Date: Sun, 1 Jun 2008 14:59:20 +0200 (CEST) Subject: [WF-CVS] [WF-git] The Ember WorldForge client. branch, lua_return_values, created. ba59c215279212d197ba2fc505c884fed5d97683 Message-ID: <20080601125921.EC0E9CD500BE@worldforge.de> The branch, lua_return_values has been created at ba59c215279212d197ba2fc505c884fed5d97683 (commit) - Log ----------------------------------------------------------------- commit ba59c215279212d197ba2fc505c884fed5d97683 Author: Erik Hjortsberg Date: Sun Jun 1 14:27:38 2008 +0200 Added the ability to get return values from script calls through the use of a script call context object. commit 4ad50b2656843c1b61a89e1fa54458350fae03c6 Author: Erik Hjortsberg Date: Sun Jun 1 14:26:40 2008 +0200 Added helper classes for handling lua return types in c++ code. commit e95f92fca8030cee57fa74b48602603cc303e26c Author: Erik Hjortsberg Date: Sat May 31 22:58:51 2008 +0200 Made the info widget a little wider to handle the full coord info. ----------------------------------------------------------------------- -- The Ember WorldForge client. From commit-messages at dark.worldforge.org Sun Jun 1 06:53:51 2008 From: commit-messages at dark.worldforge.org (commit-messages at dark.worldforge.org) Date: Sun, 1 Jun 2008 15:53:51 +0200 Subject: [WF-CVS] [WF media] r2749 - in trunk/3d_objects/environment/skyboxes: ash_hills bones_of_earth borderwood_cloudy_day dragontooth_ridge_mist Message-ID: <200806011353.m51DrpIo007271@rzcomm22.rz.tu-bs.de> Author: xrenmilay Date: Sun Jun 1 16:18:19 2008 New Revision: 2749 Log: lots of updates Removed: trunk/3d_objects/environment/skyboxes/ash_hills/D.png trunk/3d_objects/environment/skyboxes/bones_of_earth/D.png trunk/3d_objects/environment/skyboxes/borderwood_cloudy_day/D.png trunk/3d_objects/environment/skyboxes/dragontooth_ridge_mist/D.png From commit-messages at dark.worldforge.org Sun Jun 1 06:54:26 2008 From: commit-messages at dark.worldforge.org (commit-messages at dark.worldforge.org) Date: Sun, 1 Jun 2008 15:54:26 +0200 Subject: [WF-CVS] [WF media] r2750 - trunk/3d_objects/items/building_element/models/jetty Message-ID: <200806011354.m51DsQ0J007278@rzcomm22.rz.tu-bs.de> Author: xrenmilay Date: Sun Jun 1 16:18:58 2008 New Revision: 2750 Log: moving content Removed: trunk/3d_objects/items/building_element/models/jetty/ From commit-messages at dark.worldforge.org Sun Jun 1 06:55:04 2008 From: commit-messages at dark.worldforge.org (commit-messages at dark.worldforge.org) Date: Sun, 1 Jun 2008 15:55:04 +0200 Subject: [WF-CVS] [WF media] r2751 - trunk/3d_objects/plants/shrubs/leaf Message-ID: <200806011355.m51Dt4P8007281@rzcomm22.rz.tu-bs.de> Author: xrenmilay Date: Sun Jun 1 16:19:36 2008 New Revision: 2751 Log: Modified: trunk/3d_objects/plants/shrubs/leaf/N.png Modified: trunk/3d_objects/plants/shrubs/leaf/N.png ============================================================================== Binary files. No diff available. From commit-messages at dark.worldforge.org Sun Jun 1 07:03:02 2008 From: commit-messages at dark.worldforge.org (commit-messages at dark.worldforge.org) Date: Sun, 1 Jun 2008 16:03:02 +0200 Subject: [WF-CVS] [WF media] r2752 - in trunk/3d_objects/structures/textures: chopping_block ossyja ossyja_floor_planks ossyja_wall_cobblestone ozark_planks Message-ID: <200806011403.m51E32a7007935@rzcomm22.rz.tu-bs.de> Author: xrenmilay Date: Sun Jun 1 16:27:32 2008 New Revision: 2752 Log: moving content/sorting Added: trunk/3d_objects/structures/textures/ossyja_floor_planks/ trunk/3d_objects/structures/textures/ossyja_floor_planks/D.png (contents, props changed) trunk/3d_objects/structures/textures/ossyja_floor_planks/N.png (contents, props changed) trunk/3d_objects/structures/textures/ossyja_wall_cobblestone/ trunk/3d_objects/structures/textures/ossyja_wall_cobblestone/D.png (contents, props changed) trunk/3d_objects/structures/textures/ossyja_wall_cobblestone/N.png (contents, props changed) trunk/3d_objects/structures/textures/ozark_planks/ trunk/3d_objects/structures/textures/ozark_planks/D.png (contents, props changed) Removed: trunk/3d_objects/structures/textures/chopping_block/ trunk/3d_objects/structures/textures/ossyja/ Added: trunk/3d_objects/structures/textures/ossyja_floor_planks/D.png ============================================================================== Binary file. No diff available. Added: trunk/3d_objects/structures/textures/ossyja_floor_planks/N.png ============================================================================== Binary file. No diff available. Added: trunk/3d_objects/structures/textures/ossyja_wall_cobblestone/D.png ============================================================================== Binary file. No diff available. Added: trunk/3d_objects/structures/textures/ossyja_wall_cobblestone/N.png ============================================================================== Binary file. No diff available. Added: trunk/3d_objects/structures/textures/ozark_planks/D.png ============================================================================== Binary file. No diff available. From commit-messages at dark.worldforge.org Sun Jun 1 07:03:26 2008 From: commit-messages at dark.worldforge.org (commit-messages at dark.worldforge.org) Date: Sun, 1 Jun 2008 16:03:26 +0200 Subject: [WF-CVS] [WF media] r2753 - trunk/3d_objects/primitives Message-ID: <200806011403.m51E3Qmj008326@rzcomm22.rz.tu-bs.de> Author: xrenmilay Date: Sun Jun 1 16:27:59 2008 New Revision: 2753 Log: moving content Removed: trunk/3d_objects/primitives/ From commit-messages at dark.worldforge.org Sun Jun 1 07:15:28 2008 From: commit-messages at dark.worldforge.org (commit-messages at dark.worldforge.org) Date: Sun, 1 Jun 2008 16:15:28 +0200 Subject: [WF-CVS] [WF media] r2754 - in trunk/3d_objects/structures/market_tent: blue red tent_blue tent_red Message-ID: <200806011415.m51EFSdT009370@rzcomm22.rz.tu-bs.de> Author: xrenmilay Date: Sun Jun 1 16:39:58 2008 New Revision: 2754 Log: renamed textures dirs Added: trunk/3d_objects/structures/market_tent/tent_blue/ - copied from r2748, /trunk/3d_objects/structures/market_tent/blue/ trunk/3d_objects/structures/market_tent/tent_red/ - copied from r2748, /trunk/3d_objects/structures/market_tent/red/ Removed: trunk/3d_objects/structures/market_tent/blue/ trunk/3d_objects/structures/market_tent/red/ From commit-messages at dark.worldforge.org Sun Jun 1 07:19:07 2008 From: commit-messages at dark.worldforge.org (commit-messages at dark.worldforge.org) Date: Sun, 1 Jun 2008 16:19:07 +0200 Subject: [WF-CVS] [WF media] r2755 - in trunk/3d_objects/structures/marketstall: canvas_details_blue canvas_details_red canvas_main_blue canvas_main_red canvas_main_umber cavas_details_umber marketstall_details_blue marketstall_details_red marketstall_details_umber marketstall_main_blue marketstall_main_red marketstall_main_umber Message-ID: <200806011419.m51EJ7F9009821@rzcomm22.rz.tu-bs.de> Author: xrenmilay Date: Sun Jun 1 16:43:39 2008 New Revision: 2755 Log: renamed canvas section Added: trunk/3d_objects/structures/marketstall/marketstall_details_blue/ - copied from r2748, /trunk/3d_objects/structures/marketstall/canvas_details_blue/ trunk/3d_objects/structures/marketstall/marketstall_details_red/ - copied from r2748, /trunk/3d_objects/structures/marketstall/canvas_details_red/ trunk/3d_objects/structures/marketstall/marketstall_details_umber/ - copied from r2748, /trunk/3d_objects/structures/marketstall/cavas_details_umber/ trunk/3d_objects/structures/marketstall/marketstall_main_blue/ - copied from r2748, /trunk/3d_objects/structures/marketstall/canvas_main_blue/ trunk/3d_objects/structures/marketstall/marketstall_main_red/ - copied from r2748, /trunk/3d_objects/structures/marketstall/canvas_main_red/ trunk/3d_objects/structures/marketstall/marketstall_main_umber/ - copied from r2748, /trunk/3d_objects/structures/marketstall/canvas_main_umber/ Removed: trunk/3d_objects/structures/marketstall/canvas_details_blue/ trunk/3d_objects/structures/marketstall/canvas_details_red/ trunk/3d_objects/structures/marketstall/canvas_main_blue/ trunk/3d_objects/structures/marketstall/canvas_main_red/ trunk/3d_objects/structures/marketstall/canvas_main_umber/ trunk/3d_objects/structures/marketstall/cavas_details_umber/ From commit-messages at dark.worldforge.org Sun Jun 1 08:06:11 2008 From: commit-messages at dark.worldforge.org (commit-messages at dark.worldforge.org) Date: Sun, 1 Jun 2008 17:06:11 +0200 Subject: [WF-CVS] [WF media] r2756 - in trunk/3d_objects/structures/sharpened_log: birch fir sharpened_log_birch sharpened_log_fir Message-ID: <200806011506.m51F6B2h014441@rzcomm22.rz.tu-bs.de> Author: xrenmilay Date: Sun Jun 1 17:30:36 2008 New Revision: 2756 Log: renamed sharpened_log section Added: trunk/3d_objects/structures/sharpened_log/sharpened_log_birch/ - copied from r2748, /trunk/3d_objects/structures/sharpened_log/birch/ trunk/3d_objects/structures/sharpened_log/sharpened_log_fir/ - copied from r2748, /trunk/3d_objects/structures/sharpened_log/fir/ Removed: trunk/3d_objects/structures/sharpened_log/birch/ trunk/3d_objects/structures/sharpened_log/fir/ From commit-messages at dark.worldforge.org Sun Jun 1 08:08:37 2008 From: commit-messages at dark.worldforge.org (commit-messages at dark.worldforge.org) Date: Sun, 1 Jun 2008 17:08:37 +0200 Subject: [WF-CVS] [WF media] r2757 - trunk/3d_objects/structures/stone_palisade/stone_palisade Message-ID: <200806011508.m51F8bhg014903@rzcomm22.rz.tu-bs.de> Author: xrenmilay Date: Sun Jun 1 17:33:08 2008 New Revision: 2757 Log: added directory Added: trunk/3d_objects/structures/stone_palisade/stone_palisade/ From commit-messages at dark.worldforge.org Sun Jun 1 08:11:10 2008 From: commit-messages at dark.worldforge.org (commit-messages at dark.worldforge.org) Date: Sun, 1 Jun 2008 17:11:10 +0200 Subject: [WF-CVS] [WF media] r2758 - in trunk/3d_objects/structures/stone_palisade: . stone_palisade Message-ID: <200806011511.m51FBAH5014936@rzcomm22.rz.tu-bs.de> Author: xrenmilay Date: Sun Jun 1 17:34:33 2008 New Revision: 2758 Log: moved to a directory Added: trunk/3d_objects/structures/stone_palisade/stone_palisade/D.png - copied unchanged from r2748, /trunk/3d_objects/structures/stone_palisade/D.png trunk/3d_objects/structures/stone_palisade/stone_palisade/N.png - copied unchanged from r2748, /trunk/3d_objects/structures/stone_palisade/N.png trunk/3d_objects/structures/stone_palisade/stone_palisade/S.png - copied unchanged from r2748, /trunk/3d_objects/structures/stone_palisade/S.png Removed: trunk/3d_objects/structures/stone_palisade/D.png trunk/3d_objects/structures/stone_palisade/N.png trunk/3d_objects/structures/stone_palisade/S.png Modified: trunk/3d_objects/structures/stone_palisade/stone_palisade.material Modified: trunk/3d_objects/structures/stone_palisade/stone_palisade.material ============================================================================== --- trunk/3d_objects/structures/stone_palisade/stone_palisade.material (original) +++ trunk/3d_objects/structures/stone_palisade/stone_palisade.material Sun Jun 1 17:34:33 2008 @@ -12,7 +12,7 @@ texture_unit { - texture D.png + texture ..\textures\stone_palisade\D.png } diffuse 1.000000 1.000000 1.000000 From commit-messages at dark.worldforge.org Sun Jun 1 08:21:33 2008 From: commit-messages at dark.worldforge.org (commit-messages at dark.worldforge.org) Date: Sun, 1 Jun 2008 17:21:33 +0200 Subject: [WF-CVS] [WF media] r2759 - in trunk/3d_objects/structures/temple: base main roof temple_base temple_main temple_roof Message-ID: <200806011521.m51FLXHh015985@rzcomm22.rz.tu-bs.de> Author: xrenmilay Date: Sun Jun 1 17:46:05 2008 New Revision: 2759 Log: Added: trunk/3d_objects/structures/temple/temple_base/ - copied from r2748, /trunk/3d_objects/structures/temple/base/ trunk/3d_objects/structures/temple/temple_main/ - copied from r2748, /trunk/3d_objects/structures/temple/main/ trunk/3d_objects/structures/temple/temple_roof/ - copied from r2748, /trunk/3d_objects/structures/temple/roof/ Removed: trunk/3d_objects/structures/temple/base/ trunk/3d_objects/structures/temple/main/ trunk/3d_objects/structures/temple/roof/ From commit-messages at dark.worldforge.org Sun Jun 1 08:29:18 2008 From: commit-messages at dark.worldforge.org (commit-messages at dark.worldforge.org) Date: Sun, 1 Jun 2008 17:29:18 +0200 Subject: [WF-CVS] [WF media] r2760 - trunk/3d_objects/structures/wooden_fence/wooden_fence Message-ID: <200806011529.m51FTIkC016860@rzcomm22.rz.tu-bs.de> Author: xrenmilay Date: Sun Jun 1 17:53:51 2008 New Revision: 2760 Log: Added: trunk/3d_objects/structures/wooden_fence/wooden_fence/ From commit-messages at dark.worldforge.org Sun Jun 1 08:38:09 2008 From: commit-messages at dark.worldforge.org (commit-messages at dark.worldforge.org) Date: Sun, 1 Jun 2008 17:38:09 +0200 Subject: [WF-CVS] [WF media] r2761 - in trunk/3d_objects/structures/wooden_fence: . wooden_fence Message-ID: <200806011538.m51Fc9lQ017875@rzcomm22.rz.tu-bs.de> Author: xrenmilay Date: Sun Jun 1 17:59:12 2008 New Revision: 2761 Log: updated some stuff Added: trunk/3d_objects/structures/wooden_fence/wooden_fence/D.png - copied unchanged from r2748, /trunk/3d_objects/structures/wooden_fence/D.png trunk/3d_objects/structures/wooden_fence/wooden_fence/N.png - copied unchanged from r2748, /trunk/3d_objects/structures/wooden_fence/N.png trunk/3d_objects/structures/wooden_fence/wooden_fence/S.png - copied unchanged from r2748, /trunk/3d_objects/structures/wooden_fence/S.png Removed: trunk/3d_objects/structures/wooden_fence/D.png trunk/3d_objects/structures/wooden_fence/N.png trunk/3d_objects/structures/wooden_fence/S.png Modified: trunk/3d_objects/structures/wooden_fence/fence.material trunk/3d_objects/structures/wooden_fence/fence_assembly.dae trunk/3d_objects/structures/wooden_fence/fence_pole_single.dae Modified: trunk/3d_objects/structures/wooden_fence/fence.material ============================================================================== --- trunk/3d_objects/structures/wooden_fence/fence.material (original) +++ trunk/3d_objects/structures/wooden_fence/fence.material Sun Jun 1 17:59:12 2008 @@ -11,7 +11,7 @@ specular 0.8 0.8 0.8 50.000000 texture_unit { - texture D.png + texture ..\textures\wooden_fence\D.png } } @@ -31,7 +31,7 @@ specular 0.02 0.02 0.02 50.000000 texture_unit { - texture D.png + texture ..\textures\wooden_fence\D.png } } Modified: trunk/3d_objects/structures/wooden_fence/fence_assembly.dae ============================================================================== --- trunk/3d_objects/structures/wooden_fence/fence_assembly.dae (original) +++ trunk/3d_objects/structures/wooden_fence/fence_assembly.dae Sun Jun 1 17:59:12 2008 @@ -65,10 +65,10 @@ - ..\..\textures\rough_timber\timber_roughd.png + ..\textures\wooden_fence\D.png - ..\..\textures\rough_timber\beam_endd.png + ..\textures\wooden_fence\D.png Modified: trunk/3d_objects/structures/wooden_fence/fence_pole_single.dae ============================================================================== --- trunk/3d_objects/structures/wooden_fence/fence_pole_single.dae (original) +++ trunk/3d_objects/structures/wooden_fence/fence_pole_single.dae Sun Jun 1 17:59:12 2008 @@ -65,10 +65,10 @@ - ..\..\textures\rough_timber\timber_roughd.png + ..\textures\wooden_fence\D.png - ..\..\textures\rough_timber\beam_endd.png + ..\textures\wooden_fence\D.png From commitmsg at worldforge.de Sun Jun 1 11:39:07 2008 From: commitmsg at worldforge.de (commitmsg at worldforge.de) Date: Sun, 1 Jun 2008 20:39:07 +0200 (CEST) Subject: [WF-CVS] [WF-git] The Ember WorldForge client. branch, master, updated. 3206a7be9ba45cc77a3395e62a38a389aedf02eb Message-ID: <20080601183908.B3E1ECD500BC@worldforge.de> The branch, master has been updated via 3206a7be9ba45cc77a3395e62a38a389aedf02eb (commit) via 2213f1c4c7d4d3ab1a6103b7837b6f23db41cb97 (commit) via 67e82365e509ed35547d0401804d96ca836177e7 (commit) from a0154e623624111f76282ba14ed44048b4d5354d (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 3206a7be9ba45cc77a3395e62a38a389aedf02eb Author: Alexey Torkhov Date: Sun Jun 1 21:39:30 2008 +0400 Sanity fixes in Exception. commit 2213f1c4c7d4d3ab1a6103b7837b6f23db41cb97 Author: Alexey Torkhov Date: Sun May 25 00:35:59 2008 +0400 Add gnome???s anjuta specific ignores. commit 67e82365e509ed35547d0401804d96ca836177e7 Author: Alexey Torkhov Date: Sun Jun 1 21:37:40 2008 +0400 GCC 4.3 fixes. ----------------------------------------------------------------------- Summary of changes: .gitignore | 6 ++++++ src/framework/Exception.h | 7 ++++--- src/services/logging/LoggingService.h | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) Changeset truncated at 500 lines: diff --git a/.gitignore b/.gitignore index 308ba8a..9ef0987 100644 --- a/.gitignore +++ b/.gitignore @@ -31,8 +31,14 @@ var # Ignore password file used to rsync update amber rsyncpasswd # Ignore IDE user specific files +# - KDevelop *.kdevses *.pcs +# - Anjuta +.anjuta +ember.anjuta +.tm_project2.cache +TODO.tasks # Ignore libtool-generated files *.lo *.la diff --git a/src/framework/Exception.h b/src/framework/Exception.h index 4178472..008b7d0 100644 --- a/src/framework/Exception.h +++ b/src/framework/Exception.h @@ -38,8 +38,8 @@ // Included system headers #include -// #include -// #include +#include +#include namespace Ember { @@ -116,8 +116,9 @@ public: char buffer[EXCEPTION_TEXT_SIZE]; va_list va; va_start (va, line); - vsprintf(buffer, error.c_str(), va); + vsnprintf(buffer, EXCEPTION_TEXT_SIZE, error.c_str(), va); myError = buffer; + va_end (va); } diff --git a/src/services/logging/LoggingService.h b/src/services/logging/LoggingService.h index cd7716c..52431b6 100644 --- a/src/services/logging/LoggingService.h +++ b/src/services/logging/LoggingService.h @@ -25,6 +25,7 @@ #include "framework/Singleton.h" // Include library headers here +#include #include namespace Ember -- The Ember WorldForge client. From commitmsg at worldforge.de Sun Jun 1 12:18:31 2008 From: commitmsg at worldforge.de (commitmsg at worldforge.de) Date: Sun, 1 Jun 2008 21:18:31 +0200 (CEST) Subject: [WF-CVS] [WF-git] The Ember WorldForge client. branch, lua_return_values, updated. 6960d5495313fcd2d24eed47cb37f434932c443b Message-ID: <20080601191835.406F1CD500BC@worldforge.de> The branch, lua_return_values has been updated via 6960d5495313fcd2d24eed47cb37f434932c443b (commit) from ba59c215279212d197ba2fc505c884fed5d97683 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 6960d5495313fcd2d24eed47cb37f434932c443b Author: Erik Hjortsberg Date: Sun Jun 1 21:17:57 2008 +0200 Fixed some problems with how script return values were handled. ----------------------------------------------------------------------- Summary of changes: .../ogre/scripting/LuaScriptingProvider.cpp | 8 +++++--- src/framework/IScriptingProvider.h | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) Changeset truncated at 500 lines: diff --git a/src/components/ogre/scripting/LuaScriptingProvider.cpp b/src/components/ogre/scripting/LuaScriptingProvider.cpp index 7586d33..41df00e 100644 --- a/src/components/ogre/scripting/LuaScriptingProvider.cpp +++ b/src/components/ogre/scripting/LuaScriptingProvider.cpp @@ -79,8 +79,10 @@ void LuaScriptingProvider::stop() try { ///we want to clear up the lua environment without destroying it (lua_close destroys it) std::string shutdownScript("for key,value in pairs(_G) do if key ~= \"_G\" and key ~= \"pairs\" then _G[key] = nil end end"); - Ember::IScriptingCallContext callContext(createDefaultContext()); - executeScript(callContext, shutdownScript); + { + Ember::IScriptingCallContext callContext(createDefaultContext()); + executeScript(callContext, shutdownScript); + } forceGC(); } catch (...) { S_LOG_WARNING("Error when stopping lua."); @@ -241,7 +243,7 @@ void LuaScriptingProvider::executeScript(Ember::IScriptingCallContext& callConte lua_insert(mLuaState, error_index); /// load code into lua and call it - int error = lua_pcall(mLuaState,0,0,error_index); + int error = lua_pcall(mLuaState, 0, LUA_MULTRET, error_index); // handle errors if (error) diff --git a/src/framework/IScriptingProvider.h b/src/framework/IScriptingProvider.h index 6cb1df7..b58d2ee 100644 --- a/src/framework/IScriptingProvider.h +++ b/src/framework/IScriptingProvider.h @@ -31,9 +31,24 @@ namespace Ember { class ScriptingService; +// class IScriptingCallReturnValue +// { +// public: +// +// virtual operator double() = 0; +// virtual operator std::string() = 0; +// +// template +// Treturn asObject(); +// protected: +// }; + class IScriptingCallContext { public: + virtual ~IScriptingCallContext() {} +// IScriptingCallReturnValue* getReturnValue() = 0; + protected: }; -- The Ember WorldForge client. From commit-messages at dark.worldforge.org Sun Jun 1 13:34:45 2008 From: commit-messages at dark.worldforge.org (commit-messages at dark.worldforge.org) Date: Sun, 1 Jun 2008 22:34:45 +0200 Subject: [WF-CVS] [WF media] r2763 - in trunk/3d_objects/environment/skyboxes: . ash_hills bones_of_earth borderwood_cloudy_day dragontooth_ridge_day dragontooth_ridge_mist Message-ID: <200806012034.m51KYjmw016760@rzcomm22.rz.tu-bs.de> Author: xrenmilay Date: Sun Jun 1 22:59:14 2008 New Revision: 2763 Log: hashed up the skyboxes Added: trunk/3d_objects/environment/skyboxes/ash_hills.zip (contents, props changed) trunk/3d_objects/environment/skyboxes/bones_of_earth.zip (contents, props changed) trunk/3d_objects/environment/skyboxes/borderwood_cloudy_day.zip (contents, props changed) trunk/3d_objects/environment/skyboxes/dragontooth_ridge_day.zip (contents, props changed) trunk/3d_objects/environment/skyboxes/dragontooth_ridge_mist.zip (contents, props changed) trunk/3d_objects/environment/skyboxes/dragontooth_ridge_night.zip (contents, props changed) trunk/3d_objects/environment/skyboxes/dragontooth_ridge_night_starless.zip (contents, props changed) trunk/3d_objects/environment/skyboxes/elder_world.zip (contents, props changed) trunk/3d_objects/environment/skyboxes/glacier.zip (contents, props changed) trunk/3d_objects/environment/skyboxes/grey_mountains_day.zip (contents, props changed) trunk/3d_objects/environment/skyboxes/grey_mountains_night.zip (contents, props changed) trunk/3d_objects/environment/skyboxes/hobbit_hills.zip (contents, props changed) trunk/3d_objects/environment/skyboxes/japan.zip (contents, props changed) trunk/3d_objects/environment/skyboxes/lake.zip (contents, props changed) trunk/3d_objects/environment/skyboxes/mountain_ring.zip (contents, props changed) trunk/3d_objects/environment/skyboxes/nightmare.zip (contents, props changed) trunk/3d_objects/environment/skyboxes/rabbit_land.zip (contents, props changed) Removed: trunk/3d_objects/environment/skyboxes/ash_hills/ trunk/3d_objects/environment/skyboxes/bones_of_earth/ trunk/3d_objects/environment/skyboxes/borderwood_cloudy_day/ trunk/3d_objects/environment/skyboxes/dragontooth_ridge_day/ trunk/3d_objects/environment/skyboxes/dragontooth_ridge_mist/ trunk/3d_objects/environment/skyboxes/skybox.material trunk/3d_objects/environment/skyboxes/skybox.mesh Added: trunk/3d_objects/environment/skyboxes/ash_hills.zip ============================================================================== Binary file. No diff available. Added: trunk/3d_objects/environment/skyboxes/bones_of_earth.zip ============================================================================== Binary file. No diff available. Added: trunk/3d_objects/environment/skyboxes/borderwood_cloudy_day.zip ============================================================================== Binary file. No diff available. Added: trunk/3d_objects/environment/skyboxes/dragontooth_ridge_day.zip ============================================================================== Binary file. No diff available. Added: trunk/3d_objects/environment/skyboxes/dragontooth_ridge_mist.zip ============================================================================== Binary file. No diff available. Added: trunk/3d_objects/environment/skyboxes/dragontooth_ridge_night.zip ============================================================================== Binary file. No diff available. Added: trunk/3d_objects/environment/skyboxes/dragontooth_ridge_night_starless.zip ============================================================================== Binary file. No diff available. Added: trunk/3d_objects/environment/skyboxes/elder_world.zip ============================================================================== Binary file. No diff available. Added: trunk/3d_objects/environment/skyboxes/glacier.zip ============================================================================== Binary file. No diff available. Added: trunk/3d_objects/environment/skyboxes/grey_mountains_day.zip ============================================================================== Binary file. No diff available. Added: trunk/3d_objects/environment/skyboxes/grey_mountains_night.zip ============================================================================== Binary file. No diff available. Added: trunk/3d_objects/environment/skyboxes/hobbit_hills.zip ============================================================================== Binary file. No diff available. Added: trunk/3d_objects/environment/skyboxes/japan.zip ============================================================================== Binary file. No diff available. Added: trunk/3d_objects/environment/skyboxes/lake.zip ============================================================================== Binary file. No diff available. Added: trunk/3d_objects/environment/skyboxes/mountain_ring.zip ============================================================================== Binary file. No diff available. Added: trunk/3d_objects/environment/skyboxes/nightmare.zip ============================================================================== Binary file. No diff available. Added: trunk/3d_objects/environment/skyboxes/rabbit_land.zip ============================================================================== Binary file. No diff available. From commitmsg at worldforge.de Mon Jun 2 02:41:29 2008 From: commitmsg at worldforge.de (commitmsg at worldforge.de) Date: Mon, 2 Jun 2008 11:41:29 +0200 (CEST) Subject: [WF-CVS] [WF-git] The Ember WorldForge client. branch, lua_return_values, updated. fb1a92fe38680b8e310acf36b8709022d0d91cb9 Message-ID: <20080602094131.42970184A0464@worldforge.de> The branch, lua_return_values has been updated via fb1a92fe38680b8e310acf36b8709022d0d91cb9 (commit) via 3aec913355f37cb059a13a87a0c08b82da9aed4d (commit) via 3206a7be9ba45cc77a3395e62a38a389aedf02eb (commit) via 2213f1c4c7d4d3ab1a6103b7837b6f23db41cb97 (commit) via 67e82365e509ed35547d0401804d96ca836177e7 (commit) from 6960d5495313fcd2d24eed47cb37f434932c443b (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit fb1a92fe38680b8e310acf36b8709022d0d91cb9 Merge: 6960d5495313fcd2d24eed47cb37f434932c443b 3aec913355f37cb059a13a87a0c08b82da9aed4d Author: Alexey Torkhov Date: Mon Jun 2 12:59:45 2008 +0400 Merge branch 'master' into lua_return_values ----------------------------------------------------------------------- Summary of changes: .gitignore | 6 ++++++ src/framework/Exception.h | 7 ++++--- src/services/logging/LoggingService.h | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) Changeset truncated at 500 lines: diff --git a/.gitignore b/.gitignore index 308ba8a..9ef0987 100644 --- a/.gitignore +++ b/.gitignore @@ -31,8 +31,14 @@ var # Ignore password file used to rsync update amber rsyncpasswd # Ignore IDE user specific files +# - KDevelop *.kdevses *.pcs +# - Anjuta +.anjuta +ember.anjuta +.tm_project2.cache +TODO.tasks # Ignore libtool-generated files *.lo *.la diff --git a/src/framework/Exception.h b/src/framework/Exception.h index 4178472..008b7d0 100644 --- a/src/framework/Exception.h +++ b/src/framework/Exception.h @@ -38,8 +38,8 @@ // Included system headers #include -// #include -// #include +#include +#include namespace Ember { @@ -116,8 +116,9 @@ public: char buffer[EXCEPTION_TEXT_SIZE]; va_list va; va_start (va, line); - vsprintf(buffer, error.c_str(), va); + vsnprintf(buffer, EXCEPTION_TEXT_SIZE, error.c_str(), va); myError = buffer; + va_end (va); } diff --git a/src/services/logging/LoggingService.h b/src/services/logging/LoggingService.h index cd7716c..52431b6 100644 --- a/src/services/logging/LoggingService.h +++ b/src/services/logging/LoggingService.h @@ -25,6 +25,7 @@ #include "framework/Singleton.h" // Include library headers here +#include #include namespace Ember -- The Ember WorldForge client. From commitmsg at worldforge.de Mon Jun 2 02:41:31 2008 From: commitmsg at worldforge.de (commitmsg at worldforge.de) Date: Mon, 2 Jun 2008 11:41:31 +0200 (CEST) Subject: [WF-CVS] [WF-git] The Ember WorldForge client. branch, master, updated. c5e82bd58c08b2df49438a48e5aa16a8129ce79f Message-ID: <20080602094131.EA3A0184A0460@worldforge.de> The branch, master has been updated via c5e82bd58c08b2df49438a48e5aa16a8129ce79f (commit) via 3aec913355f37cb059a13a87a0c08b82da9aed4d (commit) via e95f92fca8030cee57fa74b48602603cc303e26c (commit) from 3206a7be9ba45cc77a3395e62a38a389aedf02eb (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit c5e82bd58c08b2df49438a48e5aa16a8129ce79f Author: Alexey Torkhov Date: Fri May 30 21:48:53 2008 +0400 Fixing issue with missing sighandler_t under FreeBSD. ----------------------------------------------------------------------- Summary of changes: configure.ac | 9 +++++++++ src/components/ogre/OgreSetup.h | 4 ++++ src/components/ogre/widgets/TerrainEditor.layout | 2 +- 3 files changed, 14 insertions(+), 1 deletions(-) Changeset truncated at 500 lines: diff --git a/configure.ac b/configure.ac index 57b147b..cab859f 100644 --- a/configure.ac +++ b/configure.ac @@ -41,12 +41,21 @@ AC_HEADER_STDC AC_CHECK_HEADERS(stdlib.h) AC_CHECK_HEADERS(math.h) dnl Test for header file +AC_CHECK_HEADERS([signal.h]) # Checks for typedefs, structures, and compiler characteristics. AC_C_CONST AC_C_INLINE AC_STRUCT_TM +# check sighandler_t in C++ +AC_LANG_PUSH([C++]) +AC_CHECK_TYPES([sighandler_t],[],[],[ +#ifdef HAVE_SIGNAL_H +# include +#endif]) +AC_LANG_POP([C++]) + # Checks for library functions. AC_FUNC_ERROR_AT_LINE AC_FUNC_MALLOC diff --git a/src/components/ogre/OgreSetup.h b/src/components/ogre/OgreSetup.h index ee70a51..8ec713b 100644 --- a/src/components/ogre/OgreSetup.h +++ b/src/components/ogre/OgreSetup.h @@ -23,6 +23,10 @@ #ifndef EMBEROGREOGRESETUP_H #define EMBEROGREOGRESETUP_H +#ifndef HAVE_SIGHANDLER_T +typedef void (*sighandler_t)(int); +#endif + #include "EmberOgrePrerequisites.h" struct SDL_Surface; diff --git a/src/components/ogre/widgets/TerrainEditor.layout b/src/components/ogre/widgets/TerrainEditor.layout index f084439..3b5dd7a 100644 --- a/src/components/ogre/widgets/TerrainEditor.layout +++ b/src/components/ogre/widgets/TerrainEditor.layout @@ -11,7 +11,7 @@ - + -- The Ember WorldForge client. From commitmsg at worldforge.de Mon Jun 2 05:29:58 2008 From: commitmsg at worldforge.de (commitmsg at worldforge.de) Date: Mon, 2 Jun 2008 14:29:58 +0200 (CEST) Subject: [WF-CVS] [WF-git] The Ember WorldForge client. branch, lua_return_values, updated. 6cbe5698ca5592b21c375a214087622a3cf0ad96 Message-ID: <20080602122959.AF84F184A0464@worldforge.de> The branch, lua_return_values has been updated via 6cbe5698ca5592b21c375a214087622a3cf0ad96 (commit) from fb1a92fe38680b8e310acf36b8709022d0d91cb9 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 6cbe5698ca5592b21c375a214087622a3cf0ad96 Author: Alexey Torkhov Date: Mon Jun 2 16:28:46 2008 +0400 Dereferencing objects to prevent memory leaking. But this should be done in more rebust way. ----------------------------------------------------------------------- Summary of changes: .../ogre/scripting/LuaScriptingProvider.cpp | 2 +- .../ogre/scripting/LuaScriptingProvider.h | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) Changeset truncated at 500 lines: diff --git a/src/components/ogre/scripting/LuaScriptingProvider.cpp b/src/components/ogre/scripting/LuaScriptingProvider.cpp index 41df00e..8d98d19 100644 --- a/src/components/ogre/scripting/LuaScriptingProvider.cpp +++ b/src/components/ogre/scripting/LuaScriptingProvider.cpp @@ -255,7 +255,7 @@ void LuaScriptingProvider::executeScript(Ember::IScriptingCallContext& callConte fromStack fs(mLuaState); LuaRef* luaRef = new LuaRef(fs); - luaCallContext.returnValue = luaRef; + luaCallContext.setReturnValue(luaRef); // getScriptModule().executeString(scriptCode); } catch (const CEGUI::Exception& ex) { throw Ember::Exception(ex.getMessage().c_str()); diff --git a/src/components/ogre/scripting/LuaScriptingProvider.h b/src/components/ogre/scripting/LuaScriptingProvider.h index 6b7b278..6f665b7 100644 --- a/src/components/ogre/scripting/LuaScriptingProvider.h +++ b/src/components/ogre/scripting/LuaScriptingProvider.h @@ -42,14 +42,26 @@ namespace EmberOgre { class LuaScriptingCallContext : public Ember::IScriptingCallContext { public: - LuaScriptingCallContext() : returnValue(0) + LuaScriptingCallContext() : mReturnValue(0) { } ~LuaScriptingCallContext() { - delete returnValue; + if (mReturnValue) + delete mReturnValue; } - LuaRef* returnValue; + inline void setReturnValue(LuaRef* returnValue) + { + if (mReturnValue) + delete returnValue; + mReturnValue = returnValue; + } + inline LuaRef* getReturnValue() + { + return mReturnValue; + } +protected: + LuaRef* mReturnValue; }; -- The Ember WorldForge client. From commitmsg at worldforge.de Mon Jun 2 10:02:20 2008 From: commitmsg at worldforge.de (commitmsg at worldforge.de) Date: Mon, 2 Jun 2008 19:02:20 +0200 (CEST) Subject: [WF-CVS] [WF-git] The Ember WorldForge client. branch, lua_return_values, updated. 9aaad1db63074cdf3e97b65a0d35fa7b493a912a Message-ID: <20080602170221.D29562AF7800A@worldforge.de> The branch, lua_return_values has been updated via 9aaad1db63074cdf3e97b65a0d35fa7b493a912a (commit) from 6cbe5698ca5592b21c375a214087622a3cf0ad96 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 9aaad1db63074cdf3e97b65a0d35fa7b493a912a Author: Alexey Torkhov Date: Mon Jun 2 21:02:08 2008 +0400 No need to check for NULL pointer before delete. Clean up to conform with coding standards. ----------------------------------------------------------------------- Summary of changes: .../ogre/scripting/LuaScriptingProvider.h | 44 +++++++++++-------- 1 files changed, 25 insertions(+), 19 deletions(-) Changeset truncated at 500 lines: diff --git a/src/components/ogre/scripting/LuaScriptingProvider.h b/src/components/ogre/scripting/LuaScriptingProvider.h index 6f665b7..e9cc1d9 100644 --- a/src/components/ogre/scripting/LuaScriptingProvider.h +++ b/src/components/ogre/scripting/LuaScriptingProvider.h @@ -42,29 +42,35 @@ namespace EmberOgre { class LuaScriptingCallContext : public Ember::IScriptingCallContext { public: - LuaScriptingCallContext() : mReturnValue(0) - { - } - ~LuaScriptingCallContext() - { - if (mReturnValue) - delete mReturnValue; - } - inline void setReturnValue(LuaRef* returnValue) - { - if (mReturnValue) - delete returnValue; - mReturnValue = returnValue; - } - inline LuaRef* getReturnValue() - { - return mReturnValue; - } + LuaScriptingCallContext(); + ~LuaScriptingCallContext(); + inline void setReturnValue(LuaRef* returnValue); + inline LuaRef* getReturnValue(); protected: LuaRef* mReturnValue; - }; +LuaScriptingCallContext::LuaScriptingCallContext() : mReturnValue(0) +{ +} + +LuaScriptingCallContext::~LuaScriptingCallContext() +{ + delete mReturnValue; +} + +void LuaScriptingCallContext::setReturnValue(LuaRef* returnValue) +{ + delete returnValue; + mReturnValue = returnValue; +} + +LuaRef* LuaScriptingCallContext::getReturnValue() +{ + return mReturnValue; +} + + /** @author Erik Hjortsberg */ -- The Ember WorldForge client. From cvs at mail.worldforge.org Tue Jun 3 07:12:57 2008 From: cvs at mail.worldforge.org (worldforge cvs) Date: Tue, 3 Jun 2008 10:12:57 -0400 (EDT) Subject: [WF-CVS] cvs: alriddoch Message-ID: <20080603141257.2F224140E0FF@moria.seul.org> CVSROOT: /home/cvspsrv/worldforge Module name: forge Changes by: alriddoch 08/06/03 10:12:57 Modified files: servers/cyphesis-C++: ChangeLog servers/cyphesis-C++/server: EntityFactory.cpp Log message: 2008-06-03 Al Riddoch * server/EntityFactory.cpp: Add some doc strings. From commitmsg at worldforge.de Tue Jun 3 23:20:36 2008 From: commitmsg at worldforge.de (commitmsg at worldforge.de) Date: Wed, 4 Jun 2008 08:20:36 +0200 (CEST) Subject: [WF-CVS] [WF-git] The Ember WorldForge client. branch, lua_return_values, updated. f7ed08b1a391dec7edd63d54914977c5832220a5 Message-ID: <20080604062040.8388D28F88004@worldforge.de> The branch, lua_return_values has been updated via f7ed08b1a391dec7edd63d54914977c5832220a5 (commit) from 9aaad1db63074cdf3e97b65a0d35fa7b493a912a (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit f7ed08b1a391dec7edd63d54914977c5832220a5 Author: Alexey Torkhov Date: Wed Jun 4 10:18:06 2008 +0400 Passing call context as a pointer instead of reference. Removing duplicate code. ----------------------------------------------------------------------- Summary of changes: .../ogre/scripting/LuaScriptingProvider.cpp | 87 ++++++------------- .../ogre/scripting/LuaScriptingProvider.h | 2 +- src/services/scripting/ScriptingService.cpp | 24 +----- 3 files changed, 32 insertions(+), 81 deletions(-) Changeset truncated at 500 lines: diff --git a/src/components/ogre/scripting/LuaScriptingProvider.cpp b/src/components/ogre/scripting/LuaScriptingProvider.cpp index 8d98d19..f753253 100644 --- a/src/components/ogre/scripting/LuaScriptingProvider.cpp +++ b/src/components/ogre/scripting/LuaScriptingProvider.cpp @@ -170,19 +170,24 @@ lua_State* LuaScriptingProvider::getLuaState() void LuaScriptingProvider::loadScript(Ember::ResourceWrapper& resWrapper) { + executeScript(0, std::string(resWrapper.getDataPtr(), resWrapper.getSize()), resWrapper.getName()); +} + +void LuaScriptingProvider::executeScript(Ember::IScriptingCallContext* callContext, const std::string& scriptCode, const std::string& scriptName = std::string("")) +{ try { - - // load code into lua + LuaScriptingCallContext* luaCallContext = static_cast(callContext); int top = lua_gettop(mLuaState); - int loaderr = luaL_loadbuffer(mLuaState, resWrapper.getDataPtr(), resWrapper.getSize(), resWrapper.getName().c_str()); - + int loaderr = luaL_loadbuffer(mLuaState, scriptCode.c_str(), scriptCode.length(), scriptCode.c_str()); + if (loaderr) { std::string errMsg(lua_tostring(mLuaState,-1)); lua_settop(mLuaState,top); - throw Ember::Exception("Unable to load Lua script file: '"+resWrapper.getName()+"'\n\n"+errMsg+"\n"); + //throw Ember::Exception("Unable to load Lua script file: '"+resWrapper.getName()+"'\n\n"+errMsg+"\n"); + throw Ember::Exception("Unable to load Lua script: '" + scriptCode + "'\n\n"+errMsg+"\n"); } - + ///push our error handling method before calling the code int error_index = lua_gettop(mLuaState); #if LUA51 @@ -191,83 +196,47 @@ void LuaScriptingProvider::loadScript(Ember::ResourceWrapper& resWrapper) lua_pushliteral(mLuaState, "_TRACEBACK"); lua_rawget(mLuaState, LUA_GLOBALSINDEX); /* get traceback function */ #endif - lua_insert(mLuaState, error_index);/* put it under chunk and args */ - + lua_insert(mLuaState, error_index); - // call it - if (lua_pcall(mLuaState,0,0,error_index)) + /// load code into lua and call it + int error, nresults; + int level = lua_gettop(L); // top of stack position + // if we have context to store return values, then get them + if (callContext) { - std::string errMsg(lua_tostring(mLuaState,-1)); - lua_settop(mLuaState,top); - throw Ember::Exception("Unable to execute Lua script file: '"+resWrapper.getName()+"'\n\n"+errMsg+"\n"); + error = lua_pcall(mLuaState, 0, LUA_MULTRET, error_index); + nresults = lua_gettop(L) - level; // number of results } - - lua_settop(mLuaState,top); // just in case :P - - -// getScriptModule().executeScriptFile(scriptName); - } catch (const CEGUI::Exception& ex) { - throw Ember::Exception(ex.getMessage().c_str()); - } catch( const CEGUI::String& str ) - { - throw Ember::Exception(str.c_str()); - } catch (const Ember::Exception& ex) { - throw ex; - } catch (...) { - throw Ember::Exception("Unknown error."); - } -/* } catch (const Ogre::Exception& ex) { - throw Ember::Exception("Error when loading script " + scriptName + ". Message: " + ex.get); - }*/ -} - -void LuaScriptingProvider::executeScript(Ember::IScriptingCallContext& callContext, const std::string& scriptCode) -{ - try { - LuaScriptingCallContext& luaCallContext(static_cast(callContext)); - int top = lua_gettop(mLuaState); - - - int loaderr = luaL_loadbuffer(mLuaState, scriptCode.c_str(), scriptCode.length(), scriptCode.c_str()); - - if (loaderr) + else { - std::string errMsg(lua_tostring(mLuaState,-1)); - lua_settop(mLuaState,top); - throw Ember::Exception("Unable to load Lua script: '" + scriptCode + "'\n\n"+errMsg+"\n"); + error = lua_pcall(mLuaState, 0, 0, error_index); } - - ///push our error handling method before calling the code - int error_index = lua_gettop(mLuaState); - lua_pushcfunction(mLuaState, ::EmberOgre::Scripting::LuaHelper::luaErrorHandler); - lua_insert(mLuaState, error_index); - - /// load code into lua and call it - int error = lua_pcall(mLuaState, 0, LUA_MULTRET, error_index); - + // handle errors if (error) { std::string errMsg(lua_tostring(mLuaState,-1)); lua_settop(mLuaState,top); + //throw Ember::Exception("Unable to load Lua script file: '"+resWrapper.getName()+"'\n\n"+errMsg+"\n"); throw Ember::Exception("Unable to execute Lua script string: '"+scriptCode+"'\n\n"+errMsg+"\n"); } - + fromStack fs(mLuaState); LuaRef* luaRef = new LuaRef(fs); luaCallContext.setReturnValue(luaRef); + + lua_settop(mLuaState,top); // just in case :P - do we need it? + // getScriptModule().executeString(scriptCode); } catch (const CEGUI::Exception& ex) { throw Ember::Exception(ex.getMessage().c_str()); - } catch( const CEGUI::String& str ) - { + } catch( const CEGUI::String& str ) { throw Ember::Exception(str.c_str()); } catch (const Ember::Exception& ex) { throw ex; } catch (...) { throw Ember::Exception("Unknown error."); } - } bool LuaScriptingProvider::willLoadScript(const std::string& scriptName) diff --git a/src/components/ogre/scripting/LuaScriptingProvider.h b/src/components/ogre/scripting/LuaScriptingProvider.h index e9cc1d9..80acf54 100644 --- a/src/components/ogre/scripting/LuaScriptingProvider.h +++ b/src/components/ogre/scripting/LuaScriptingProvider.h @@ -93,7 +93,7 @@ public: * Executes the supplied string directly into the scripting environment. * @param scriptCode */ - virtual void executeScript(Ember::IScriptingCallContext& callContext, const std::string& scriptCode); + virtual void executeScript(Ember::IScriptingCallContext* callContext, const std::string& scriptCode); /** * Returns true if the provider will load the supplied script name. This is in most cases decided from the filename suffix. diff --git a/src/services/scripting/ScriptingService.cpp b/src/services/scripting/ScriptingService.cpp index 48ec924..fc368f6 100644 --- a/src/services/scripting/ScriptingService.cpp +++ b/src/services/scripting/ScriptingService.cpp @@ -100,35 +100,17 @@ void ScriptingService::loadScript(const std::string& script) void ScriptingService::executeCode(const std::string& scriptCode, const std::string& scriptType) { - - ProviderStore::iterator I = mProviders.find(scriptType); - if (I == mProviders.end()) { - S_LOG_FAILURE("There is no scripting provider with the name \"" << scriptType << "\""); - } else { - try { - IScriptingCallContext callContext(I->second->createDefaultContext()); - I->second->executeScript(callContext, scriptCode); - } catch (const Ember::Exception& ex) { - S_LOG_WARNING("Error when executing script\n" << scriptCode << "\nwith provider " << I->second->getName() << ". Message: " << ex.getError()); - scriptError(ex.getError()); - } catch (const std::exception& ex) { - S_LOG_WARNING("Error when executing script\n" << scriptCode << "\nwith provider " << I->second->getName() << ". Message: " << ex.what()); - scriptError(ex.what()); - } catch (...) { - S_LOG_WARNING("Got unknown script error when executing the script " << scriptCode); - scriptError("Unknown error executing script."); - } - } + executeCode(0, scriptCode, scriptType); } -void ScriptingService::executeCode(IScriptingCallContext& callContext, const std::string& scriptCode, const std::string& scriptType) +void ScriptingService::executeCode(IScriptingCallContext* callContext, const std::string& scriptCode, const std::string& scriptType) { ProviderStore::iterator I = mProviders.find(scriptType); if (I == mProviders.end()) { S_LOG_FAILURE("There is no scripting provider with the name \"" << scriptType << "\""); } else { try { - I->second->executeScript(callContext, scriptCode); + I->second->executeScript(0, scriptCode); } catch (const Ember::Exception& ex) { S_LOG_WARNING("Error when executing script\n" << scriptCode << "\nwith provider " << I->second->getName() << ". Message: " << ex.getError()); scriptError(ex.getError()); -- The Ember WorldForge client. From cvs at mail.worldforge.org Wed Jun 4 10:23:54 2008 From: cvs at mail.worldforge.org (worldforge cvs) Date: Wed, 4 Jun 2008 13:23:54 -0400 (EDT) Subject: [WF-CVS] cvs: alex Message-ID: <20080604172354.490281411621@moria.seul.org> CVSROOT: /home/cvspsrv/worldforge Module name: forge Changes by: alex 08/06/04 13:23:54 Modified files: libs/libwfut : ChangeLog configure.ac libs/libwfut/libwfut: ChannelParser.cpp FileParser.cpp Makefile.am tinyxml.cpp tinyxml.h libs/libwfut/tinyxml: tinyxml.h libs/libwfut/tools: Makefile.am Log message: Last patch was applied to wrong incarnation of tinyxml. This is right one. Also this fixes compatibility with new version of tinyxml and compile problem. From cvs at mail.worldforge.org Wed Jun 4 11:02:38 2008 From: cvs at mail.worldforge.org (worldforge cvs) Date: Wed, 4 Jun 2008 14:02:38 -0400 (EDT) Subject: [WF-CVS] cvs: alriddoch Message-ID: <20080604180238.1EC54140F170@moria.seul.org> CVSROOT: /home/cvspsrv/worldforge Module name: forge Changes by: alriddoch 08/06/04 14:02:38 Modified files: servers/cyphesis-C++: ChangeLog Makefile.am servers/cyphesis-C++/libraries: Makefile.am Log message: 2008-06-04 Al Riddoch * Makefile.am, libraries/Makefile.am: Fix the recursive rules so a complete distribution package is built. From cvs at mail.worldforge.org Wed Jun 4 16:29:12 2008 From: cvs at mail.worldforge.org (worldforge cvs) Date: Wed, 4 Jun 2008 19:29:12 -0400 (EDT) Subject: [WF-CVS] cvs: alriddoch Message-ID: <20080604232912.12075140A692@moria.seul.org> CVSROOT: /home/cvspsrv/worldforge Module name: forge Changes by: alriddoch 08/06/04 19:29:12 Modified files: servers/cyphesis-C++: ChangeLog servers/cyphesis-C++/tests: Containertest.cpp PropertyExerciser.cpp Log message: 2008-06-05 Al Riddoch * tests/PropertyExerciser.cpp: Use the C++ limits API, rather than the C defines. * tests/Containertest.cpp: Add missing C headers required by more recent compilers. From commitmsg at worldforge.de Thu Jun 5 10:05:05 2008 From: commitmsg at worldforge.de (commitmsg at worldforge.de) Date: Thu, 5 Jun 2008 19:05:05 +0200 (CEST) Subject: [WF-CVS] [WF-git] The Ember WorldForge client. branch, lua_return_values, updated. 81c15841b03498c330fc44575e10390e5b46865b Message-ID: <20080605170506.21C9D184A0462@worldforge.de> The branch, lua_return_values has been updated via 81c15841b03498c330fc44575e10390e5b46865b (commit) from f7ed08b1a391dec7edd63d54914977c5832220a5 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 81c15841b03498c330fc44575e10390e5b46865b Author: Alexey Torkhov Date: Thu Jun 5 20:56:04 2008 +0400 Make it compilable. ----------------------------------------------------------------------- Summary of changes: .../ogre/scripting/LuaScriptingProvider.cpp | 38 +++++++++++++------ .../ogre/scripting/LuaScriptingProvider.h | 6 ++-- src/framework/IScriptingProvider.h | 2 +- src/services/scripting/ScriptingService.h | 2 +- 4 files changed, 31 insertions(+), 17 deletions(-) Changeset truncated at 500 lines: diff --git a/src/components/ogre/scripting/LuaScriptingProvider.cpp b/src/components/ogre/scripting/LuaScriptingProvider.cpp index f753253..684ba7c 100644 --- a/src/components/ogre/scripting/LuaScriptingProvider.cpp +++ b/src/components/ogre/scripting/LuaScriptingProvider.cpp @@ -80,8 +80,7 @@ void LuaScriptingProvider::stop() ///we want to clear up the lua environment without destroying it (lua_close destroys it) std::string shutdownScript("for key,value in pairs(_G) do if key ~= \"_G\" and key ~= \"pairs\" then _G[key] = nil end end"); { - Ember::IScriptingCallContext callContext(createDefaultContext()); - executeScript(callContext, shutdownScript); + executeScript(0, shutdownScript); } forceGC(); } catch (...) { @@ -173,7 +172,7 @@ void LuaScriptingProvider::loadScript(Ember::ResourceWrapper& resWrapper) executeScript(0, std::string(resWrapper.getDataPtr(), resWrapper.getSize()), resWrapper.getName()); } -void LuaScriptingProvider::executeScript(Ember::IScriptingCallContext* callContext, const std::string& scriptCode, const std::string& scriptName = std::string("")) +void LuaScriptingProvider::executeScript(Ember::IScriptingCallContext* callContext, const std::string& scriptCode, const std::string& scriptName) { try { LuaScriptingCallContext* luaCallContext = static_cast(callContext); @@ -184,8 +183,14 @@ void LuaScriptingProvider::executeScript(Ember::IScriptingCallContext* callConte { std::string errMsg(lua_tostring(mLuaState,-1)); lua_settop(mLuaState,top); - //throw Ember::Exception("Unable to load Lua script file: '"+resWrapper.getName()+"'\n\n"+errMsg+"\n"); - throw Ember::Exception("Unable to load Lua script: '" + scriptCode + "'\n\n"+errMsg+"\n"); + if (!scriptName.empty()) + { + throw Ember::Exception("Unable to load Lua script file: '"+scriptName+"'\n\n"+errMsg+"\n"); + } + else + { + throw Ember::Exception("Unable to load Lua script: '" + scriptCode + "'\n\n"+errMsg+"\n"); + } } ///push our error handling method before calling the code @@ -200,12 +205,12 @@ void LuaScriptingProvider::executeScript(Ember::IScriptingCallContext* callConte /// load code into lua and call it int error, nresults; - int level = lua_gettop(L); // top of stack position + int level = lua_gettop(mLuaState); // top of stack position // if we have context to store return values, then get them if (callContext) { error = lua_pcall(mLuaState, 0, LUA_MULTRET, error_index); - nresults = lua_gettop(L) - level; // number of results + nresults = lua_gettop(mLuaState) - level; // number of results } else { @@ -217,13 +222,22 @@ void LuaScriptingProvider::executeScript(Ember::IScriptingCallContext* callConte { std::string errMsg(lua_tostring(mLuaState,-1)); lua_settop(mLuaState,top); - //throw Ember::Exception("Unable to load Lua script file: '"+resWrapper.getName()+"'\n\n"+errMsg+"\n"); - throw Ember::Exception("Unable to execute Lua script string: '"+scriptCode+"'\n\n"+errMsg+"\n"); + if (!scriptName.empty()) + { + throw Ember::Exception("Unable to load Lua script file: '"+scriptName+"'\n\n"+errMsg+"\n"); + } + else + { + throw Ember::Exception("Unable to load Lua script: '" + scriptCode + "'\n\n"+errMsg+"\n"); + } } - fromStack fs(mLuaState); - LuaRef* luaRef = new LuaRef(fs); - luaCallContext.setReturnValue(luaRef); + if (callContext) + { + fromStack fs(mLuaState); + LuaRef* luaRef = new LuaRef(fs); + luaCallContext->setReturnValue(luaRef); + } lua_settop(mLuaState,top); // just in case :P - do we need it? diff --git a/src/components/ogre/scripting/LuaScriptingProvider.h b/src/components/ogre/scripting/LuaScriptingProvider.h index 80acf54..b7e7a4a 100644 --- a/src/components/ogre/scripting/LuaScriptingProvider.h +++ b/src/components/ogre/scripting/LuaScriptingProvider.h @@ -42,8 +42,8 @@ namespace EmberOgre { class LuaScriptingCallContext : public Ember::IScriptingCallContext { public: - LuaScriptingCallContext(); - ~LuaScriptingCallContext(); + inline LuaScriptingCallContext(); + inline ~LuaScriptingCallContext(); inline void setReturnValue(LuaRef* returnValue); inline LuaRef* getReturnValue(); protected: @@ -93,7 +93,7 @@ public: * Executes the supplied string directly into the scripting environment. * @param scriptCode */ - virtual void executeScript(Ember::IScriptingCallContext* callContext, const std::string& scriptCode); + virtual void executeScript(Ember::IScriptingCallContext* callContext, const std::string& scriptCode, const std::string& scriptName = std::string("")); /** * Returns true if the provider will load the supplied script name. This is in most cases decided from the filename suffix. diff --git a/src/framework/IScriptingProvider.h b/src/framework/IScriptingProvider.h index b58d2ee..0fd463e 100644 --- a/src/framework/IScriptingProvider.h +++ b/src/framework/IScriptingProvider.h @@ -73,7 +73,7 @@ public: * Executes the supplied string directly into the scripting environment. * @param scriptCode */ - virtual void executeScript(IScriptingCallContext& callContext, const std::string& scriptCode) = 0; + virtual void executeScript(Ember::IScriptingCallContext* callContext, const std::string& scriptCode, const std::string& scriptName = std::string("")) = 0; /** diff --git a/src/services/scripting/ScriptingService.h b/src/services/scripting/ScriptingService.h index fddd8fb..eb77e9c 100644 --- a/src/services/scripting/ScriptingService.h +++ b/src/services/scripting/ScriptingService.h @@ -77,7 +77,7 @@ public: * @param scriptType */ void executeCode(const std::string& scriptCode, const std::string& scriptType); - void executeCode(IScriptingCallContext& callContext, const std::string& scriptCode, const std::string& scriptType); + void executeCode(IScriptingCallContext* callContext, const std::string& scriptCode, const std::string& scriptType); /** * The EventScriptError signal will be emitted when there is an error in a script. -- The Ember WorldForge client. From commitmsg at worldforge.de Thu Jun 5 12:16:10 2008 From: commitmsg at worldforge.de (commitmsg at worldforge.de) Date: Thu, 5 Jun 2008 21:16:10 +0200 (CEST) Subject: [WF-CVS] [WF-git] The Ember WorldForge client. branch, lua_return_values, updated. afb99e0caa016f8121bc954be9085da275780cd4 Message-ID: <20080605191611.7C383184A0462@worldforge.de> The branch, lua_return_values has been updated via afb99e0caa016f8121bc954be9085da275780cd4 (commit) from 81c15841b03498c330fc44575e10390e5b46865b (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit afb99e0caa016f8121bc954be9085da275780cd4 Author: Erik Hjortsberg Date: Thu Jun 5 21:15:09 2008 +0200 Moved the constructor and destructor to .cpp file to fix linking errors. Also added more comments and made it use the sent in context when executing scripts. ----------------------------------------------------------------------- Summary of changes: .../ogre/scripting/LuaScriptingProvider.cpp | 12 ++++++++- .../ogre/scripting/LuaScriptingProvider.h | 28 +++++++++---------- src/services/scripting/ScriptingService.cpp | 2 +- 3 files changed, 25 insertions(+), 17 deletions(-) Changeset truncated at 500 lines: diff --git a/src/components/ogre/scripting/LuaScriptingProvider.cpp b/src/components/ogre/scripting/LuaScriptingProvider.cpp index 684ba7c..5d8d6e0 100644 --- a/src/components/ogre/scripting/LuaScriptingProvider.cpp +++ b/src/components/ogre/scripting/LuaScriptingProvider.cpp @@ -175,7 +175,7 @@ void LuaScriptingProvider::loadScript(Ember::ResourceWrapper& resWrapper) void LuaScriptingProvider::executeScript(Ember::IScriptingCallContext* callContext, const std::string& scriptCode, const std::string& scriptName) { try { - LuaScriptingCallContext* luaCallContext = static_cast(callContext); + LuaScriptingCallContext* luaCallContext(static_cast(callContext)); int top = lua_gettop(mLuaState); int loaderr = luaL_loadbuffer(mLuaState, scriptCode.c_str(), scriptCode.length(), scriptCode.c_str()); @@ -322,4 +322,14 @@ void LuaScriptingProvider::forceGC() // return mLuaScriptModule; // } + +LuaScriptingCallContext::LuaScriptingCallContext() : mReturnValue(0) +{ +} + +LuaScriptingCallContext::~LuaScriptingCallContext() +{ + delete mReturnValue; +} + } diff --git a/src/components/ogre/scripting/LuaScriptingProvider.h b/src/components/ogre/scripting/LuaScriptingProvider.h index b7e7a4a..0870b6d 100644 --- a/src/components/ogre/scripting/LuaScriptingProvider.h +++ b/src/components/ogre/scripting/LuaScriptingProvider.h @@ -50,15 +50,6 @@ protected: LuaRef* mReturnValue; }; -LuaScriptingCallContext::LuaScriptingCallContext() : mReturnValue(0) -{ -} - -LuaScriptingCallContext::~LuaScriptingCallContext() -{ - delete mReturnValue; -} - void LuaScriptingCallContext::setReturnValue(LuaRef* returnValue) { delete returnValue; @@ -72,6 +63,9 @@ LuaRef* LuaScriptingCallContext::getReturnValue() /** + at brief A scripting provider for Lua. + +This acts as a bridge between Ember and the Lua scripting environment. Opon creation and destruction it will take care of setting up and tearing down the lua virtual machine. Remember to call @see stop() before deleting an instance of this to make sure that everyting is properly cleaned up. @author Erik Hjortsberg */ class LuaScriptingProvider : public Ember::IScriptingProvider @@ -120,15 +114,19 @@ public: virtual void forceGC(); // virtual void start(); + + + /** + * @brief Stops the lua environment, which mainly means that all objects are destroyed. + * Call this before this object is destroyed to make sure that all held objects and references are properly released. If not, there's a risk of dangling pointers. + */ virtual void stop(); - /** - * Returns the scripting module - * @return - */ -// CEGUI::ScriptModule& getScriptModule(); - + /** + * Gets the current lua state. This will always return a valid lua virtual machine, but note that if @see stop() already has been called it will porbably be in an invalid state. + * @return The current lua environment. + */ lua_State* getLuaState(); diff --git a/src/services/scripting/ScriptingService.cpp b/src/services/scripting/ScriptingService.cpp index fc368f6..c16908b 100644 --- a/src/services/scripting/ScriptingService.cpp +++ b/src/services/scripting/ScriptingService.cpp @@ -110,7 +110,7 @@ void ScriptingService::executeCode(IScriptingCallContext* callContext, const std S_LOG_FAILURE("There is no scripting provider with the name \"" << scriptType << "\""); } else { try { - I->second->executeScript(0, scriptCode); + I->second->executeScript(callContext, scriptCode); } catch (const Ember::Exception& ex) { S_LOG_WARNING("Error when executing script\n" << scriptCode << "\nwith provider " << I->second->getName() << ". Message: " << ex.getError()); scriptError(ex.getError()); -- The Ember WorldForge client. From commitmsg at worldforge.de Thu Jun 5 12:16:11 2008 From: commitmsg at worldforge.de (commitmsg at worldforge.de) Date: Thu, 5 Jun 2008 21:16:11 +0200 (CEST) Subject: [WF-CVS] [WF-git] The Ember WorldForge client. branch, master, updated. 2af9a5994ad9806867d88cf30c86d09448465921 Message-ID: <20080605191612.1F761184A0464@worldforge.de> The branch, master has been updated via 2af9a5994ad9806867d88cf30c86d09448465921 (commit) via 06632b6236df092fac35d93817a0683356040904 (commit) from c5e82bd58c08b2df49438a48e5aa16a8129ce79f (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 2af9a5994ad9806867d88cf30c86d09448465921 Merge: 06632b6236df092fac35d93817a0683356040904 c5e82bd58c08b2df49438a48e5aa16a8129ce79f Author: Erik Hjortsberg Date: Mon Jun 2 20:59:30 2008 +0200 Merge branch 'master' of ssh://jade.worldforge.org/data/git/ember commit 06632b6236df092fac35d93817a0683356040904 Merge: e95f92fca8030cee57fa74b48602603cc303e26c 3206a7be9ba45cc77a3395e62a38a389aedf02eb Author: Erik Hjortsberg Date: Sun Jun 1 21:26:25 2008 +0200 Merge branch 'master' of ssh://jade.worldforge.org/data/git/ember ----------------------------------------------------------------------- Summary of changes: Changeset truncated at 500 lines: -- The Ember WorldForge client. From commitmsg at worldforge.de Thu Jun 5 13:11:47 2008 From: commitmsg at worldforge.de (commitmsg at worldforge.de) Date: Thu, 5 Jun 2008 22:11:47 +0200 (CEST) Subject: [WF-CVS] [WF-git] The Ember WorldForge client. branch, lua_return_values, updated. 1b88d0b0b88e9e2c7fb6d144d1ac6b9f25519925 Message-ID: <20080605201148.3A445184A0464@worldforge.de> The branch, lua_return_values has been updated via 1b88d0b0b88e9e2c7fb6d144d1ac6b9f25519925 (commit) from afb99e0caa016f8121bc954be9085da275780cd4 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 1b88d0b0b88e9e2c7fb6d144d1ac6b9f25519925 Author: Erik Hjortsberg Date: Thu Jun 5 22:11:10 2008 +0200 Cleaned up the api a little bit. Since the context is optional we want to put that as the last parameter. ----------------------------------------------------------------------- Summary of changes: .../ogre/scripting/LuaScriptingProvider.cpp | 22 ++++++------ .../ogre/scripting/LuaScriptingProvider.h | 37 +++++++++++++------- src/framework/IScriptingProvider.h | 25 +++++++------ src/services/scripting/ScriptingService.cpp | 9 +---- src/services/scripting/ScriptingService.h | 3 +- 5 files changed, 52 insertions(+), 44 deletions(-) Changeset truncated at 500 lines: diff --git a/src/components/ogre/scripting/LuaScriptingProvider.cpp b/src/components/ogre/scripting/LuaScriptingProvider.cpp index 5d8d6e0..03617d8 100644 --- a/src/components/ogre/scripting/LuaScriptingProvider.cpp +++ b/src/components/ogre/scripting/LuaScriptingProvider.cpp @@ -80,7 +80,7 @@ void LuaScriptingProvider::stop() ///we want to clear up the lua environment without destroying it (lua_close destroys it) std::string shutdownScript("for key,value in pairs(_G) do if key ~= \"_G\" and key ~= \"pairs\" then _G[key] = nil end end"); { - executeScript(0, shutdownScript); + executeScript(shutdownScript, 0); } forceGC(); } catch (...) { @@ -169,13 +169,18 @@ lua_State* LuaScriptingProvider::getLuaState() void LuaScriptingProvider::loadScript(Ember::ResourceWrapper& resWrapper) { - executeScript(0, std::string(resWrapper.getDataPtr(), resWrapper.getSize()), resWrapper.getName()); + executeScriptImpl(std::string(resWrapper.getDataPtr(), resWrapper.getSize()), 0, resWrapper.getName()); } -void LuaScriptingProvider::executeScript(Ember::IScriptingCallContext* callContext, const std::string& scriptCode, const std::string& scriptName) +void LuaScriptingProvider::executeScript(const std::string& scriptCode, Ember::IScriptingCallContext* callContext) +{ + + executeScriptImpl(scriptCode, static_cast(callContext), ""); +} + +void LuaScriptingProvider::executeScriptImpl(const std::string& scriptCode, LuaScriptingCallContext* luaCallContext, const std::string& scriptName) { try { - LuaScriptingCallContext* luaCallContext(static_cast(callContext)); int top = lua_gettop(mLuaState); int loaderr = luaL_loadbuffer(mLuaState, scriptCode.c_str(), scriptCode.length(), scriptCode.c_str()); @@ -207,7 +212,7 @@ void LuaScriptingProvider::executeScript(Ember::IScriptingCallContext* callConte int error, nresults; int level = lua_gettop(mLuaState); // top of stack position // if we have context to store return values, then get them - if (callContext) + if (luaCallContext) { error = lua_pcall(mLuaState, 0, LUA_MULTRET, error_index); nresults = lua_gettop(mLuaState) - level; // number of results @@ -232,7 +237,7 @@ void LuaScriptingProvider::executeScript(Ember::IScriptingCallContext* callConte } } - if (callContext) + if (luaCallContext) { fromStack fs(mLuaState); LuaRef* luaRef = new LuaRef(fs); @@ -272,11 +277,6 @@ void LuaScriptingProvider::_registerWithService(Ember::ScriptingService* service mService = service; } -Ember::IScriptingCallContext LuaScriptingProvider::createDefaultContext() -{ - return LuaScriptingCallContext(); -} - void LuaScriptingProvider::forceGC() { diff --git a/src/components/ogre/scripting/LuaScriptingProvider.h b/src/components/ogre/scripting/LuaScriptingProvider.h index 0870b6d..f31b255 100644 --- a/src/components/ogre/scripting/LuaScriptingProvider.h +++ b/src/components/ogre/scripting/LuaScriptingProvider.h @@ -66,6 +66,8 @@ LuaRef* LuaScriptingCallContext::getReturnValue() @brief A scripting provider for Lua. This acts as a bridge between Ember and the Lua scripting environment. Opon creation and destruction it will take care of setting up and tearing down the lua virtual machine. Remember to call @see stop() before deleting an instance of this to make sure that everyting is properly cleaned up. + +If you want to inspect the return values from calls to lua scripts, pass a pointer to @see LuaScriptingCallContext to the executeScript methods. @author Erik Hjortsberg */ class LuaScriptingProvider : public Ember::IScriptingProvider @@ -74,42 +76,42 @@ public: LuaScriptingProvider(); virtual ~LuaScriptingProvider(); - - virtual Ember::IScriptingCallContext createDefaultContext(); - + /** - * Loads the script. - * @param scriptName + * @brief Loads the script from the wrapper. + * @param resourceWrapper A resource wrapper pointing to a valid resource which can be loaded. This should contain a text file with the script contents. */ virtual void loadScript(Ember::ResourceWrapper& resWrapper); /** - * Executes the supplied string directly into the scripting environment. - * @param scriptCode + * @brief Executes the supplied string directly into the scripting environment. + * Optionally a pointer to a scripting call context can be submitted too, which will then be populated with return values and other scripting environment specific info. + * @param scriptCode The code to excute. + * @param callContext An optional pointer to a scripting call context. This will be populated with return values and other info. If you don't have any need for such info, leave this empty. */ - virtual void executeScript(Ember::IScriptingCallContext* callContext, const std::string& scriptCode, const std::string& scriptName = std::string("")); + virtual void executeScript(const std::string& scriptCode, Ember::IScriptingCallContext* callContext); /** - * Returns true if the provider will load the supplied script name. This is in most cases decided from the filename suffix. + * @brief Returns true if the provider will load the supplied script name. This is in most cases decided from the filename suffix. * @param scriptName * @return */ virtual bool willLoadScript(const std::string& scriptName); /** - * Gets the unique name of the scripting provider. + * @brief Gets the unique name of the scripting provider. * @return */ virtual const std::string& getName() const; /** - * Register with a service to allow for callbacks etc. + * @brief Register with a service to allow for callbacks etc. * @param service */ virtual void _registerWithService(Ember::ScriptingService* service); /** - * Forces a full garbage collection. + * @brief Forces a full garbage collection. */ virtual void forceGC(); @@ -124,7 +126,8 @@ public: /** - * Gets the current lua state. This will always return a valid lua virtual machine, but note that if @see stop() already has been called it will porbably be in an invalid state. + * @brief Gets the current lua state. + * This will always return a valid lua virtual machine, but note that if @see stop() already has been called it will porbably be in an invalid state. * @return The current lua environment. */ lua_State* getLuaState(); @@ -132,6 +135,14 @@ public: private: + /** + * @brief Executes the supplied script code. + * @param scriptCode The code to execute. + * @param luaCallContext An optional lua call context, which if present will contain any return values. + * @param scriptName The name of the script, mainly used for debugging purpose. + */ + void executeScriptImpl(const std::string& scriptCode, LuaScriptingCallContext* luaCallContext, const std::string& scriptName = std::string("")); + void initialize(); void createState(); // std::auto_ptr mLuaScriptModule; diff --git a/src/framework/IScriptingProvider.h b/src/framework/IScriptingProvider.h index 0fd463e..7382e8a 100644 --- a/src/framework/IScriptingProvider.h +++ b/src/framework/IScriptingProvider.h @@ -60,49 +60,52 @@ public: virtual ~IScriptingProvider(){} - virtual IScriptingCallContext createDefaultContext() = 0; +// virtual IScriptingCallContext createDefaultContext() = 0; /** - * Loads the script. - * @param scriptName + * @brief Loads the script from the wrapper. + * @param resourceWrapper A resource wrapper pointing to a valid resource which can be loaded. This should contain a text file with the script contents. */ virtual void loadScript(ResourceWrapper& resourceWrapper) = 0; /** - * Executes the supplied string directly into the scripting environment. - * @param scriptCode + * @brief Executes the supplied string directly into the scripting environment. + * Optionally a pointer to a scripting call context can be submitted too, which will then be populated with return values and other scripting environment specific info. + * @param scriptCode The code to excute. + * @param callContext An optional pointer to a scripting call context. This will be populated with return values and other info. If you don't have any need for such info, leave this empty. */ - virtual void executeScript(Ember::IScriptingCallContext* callContext, const std::string& scriptCode, const std::string& scriptName = std::string("")) = 0; + virtual void executeScript(const std::string& scriptCode, Ember::IScriptingCallContext* callContext) = 0; /** - * Returns true if the provider will load the supplied script name. This is in most cases decided from the filename suffix. + * @brief Returns true if the provider will load the supplied script name. This is in most cases decided from the filename suffix. * @param scriptName * @return */ virtual bool willLoadScript(const std::string& scriptName) = 0; /** - * Gets the unique name of the scripting provider. + * @brief Gets the unique name of the scripting provider. * @return */ virtual const std::string& getName() const = 0; /** - * Register with a service to allow for callbacks etc. + * @brief Register with a service to allow for callbacks etc. * @param service */ virtual void _registerWithService(ScriptingService* service) = 0; /** - * Forces a full garbage collection. + * @brief Forces a full garbage collection. */ virtual void forceGC() = 0; // virtual void start() = 0; /** - * Stops the scripting provider. This involves releasing all of the objects held in scripts, but not destroying the actual scripting environment (so that callbacks and similiar objects still can use it). + * @brief Stops the scripting provider. + * This involves releasing all of the objects held in scripts, but not destroying the actual scripting environment (so that callbacks and similiar objects still can use it). */ virtual void stop() = 0; diff --git a/src/services/scripting/ScriptingService.cpp b/src/services/scripting/ScriptingService.cpp index c16908b..ae7ac50 100644 --- a/src/services/scripting/ScriptingService.cpp +++ b/src/services/scripting/ScriptingService.cpp @@ -98,19 +98,14 @@ void ScriptingService::loadScript(const std::string& script) } } -void ScriptingService::executeCode(const std::string& scriptCode, const std::string& scriptType) -{ - executeCode(0, scriptCode, scriptType); -} - -void ScriptingService::executeCode(IScriptingCallContext* callContext, const std::string& scriptCode, const std::string& scriptType) +void ScriptingService::executeCode(const std::string& scriptCode, const std::string& scriptType, IScriptingCallContext* callContext) { ProviderStore::iterator I = mProviders.find(scriptType); if (I == mProviders.end()) { S_LOG_FAILURE("There is no scripting provider with the name \"" << scriptType << "\""); } else { try { - I->second->executeScript(callContext, scriptCode); + I->second->executeScript(scriptCode, callContext); } catch (const Ember::Exception& ex) { S_LOG_WARNING("Error when executing script\n" << scriptCode << "\nwith provider " << I->second->getName() << ". Message: " << ex.getError()); scriptError(ex.getError()); diff --git a/src/services/scripting/ScriptingService.h b/src/services/scripting/ScriptingService.h index eb77e9c..271d390 100644 --- a/src/services/scripting/ScriptingService.h +++ b/src/services/scripting/ScriptingService.h @@ -76,8 +76,7 @@ public: * @param scriptCode * @param scriptType */ - void executeCode(const std::string& scriptCode, const std::string& scriptType); - void executeCode(IScriptingCallContext* callContext, const std::string& scriptCode, const std::string& scriptType); + void executeCode(const std::string& scriptCode, const std::string& scriptType, IScriptingCallContext* callContext = 0); /** * The EventScriptError signal will be emitted when there is an error in a script. -- The Ember WorldForge client. From commitmsg at worldforge.de Thu Jun 5 13:45:25 2008 From: commitmsg at worldforge.de (commitmsg at worldforge.de) Date: Thu, 5 Jun 2008 22:45:25 +0200 (CEST) Subject: [WF-CVS] [WF-git] The Ember WorldForge client. branch, lua_return_values, updated. 1e6e518ec55824e0ef64dd80ca84c36ff6769017 Message-ID: <20080605204539.9BAF628F88004@worldforge.de> The branch, lua_return_values has been updated via 1e6e518ec55824e0ef64dd80ca84c36ff6769017 (commit) from 1b88d0b0b88e9e2c7fb6d144d1ac6b9f25519925 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 1e6e518ec55824e0ef64dd80ca84c36ff6769017 Author: Erik Hjortsberg Date: Thu Jun 5 22:44:42 2008 +0200 Moved the lua scripting call context to its own file. ----------------------------------------------------------------------- Summary of changes: .../ogre/scripting/LuaScriptingCallContext.cpp} | 15 +++-- .../ogre/scripting/LuaScriptingCallContext.h | 73 ++++++++++++++++++++ .../ogre/scripting/LuaScriptingProvider.cpp | 8 +-- .../ogre/scripting/LuaScriptingProvider.h | 24 +------ src/components/ogre/scripting/Makefile.am | 4 +- 5 files changed, 87 insertions(+), 37 deletions(-) copy src/{services/logging/Observer.cpp => components/ogre/scripting/LuaScriptingCallContext.cpp} (77%) create mode 100644 src/components/ogre/scripting/LuaScriptingCallContext.h Changeset truncated at 500 lines: diff --git a/src/services/logging/Observer.cpp b/src/components/ogre/scripting/LuaScriptingCallContext.cpp similarity index 77% copy from src/services/logging/Observer.cpp copy to src/components/ogre/scripting/LuaScriptingCallContext.cpp index 0c72340..6217d29 100644 --- a/src/services/logging/Observer.cpp +++ b/src/components/ogre/scripting/LuaScriptingCallContext.cpp @@ -1,5 +1,5 @@ // -// C++ Implementation: Observer +// C++ Implementation: LuaScriptingCallContext // // Description: // @@ -24,13 +24,18 @@ #include "config.h" #endif -#include "Observer.h" +#include "LuaScriptingCallContext.h" -namespace Ember { - -namespace LogginService { +namespace EmberOgre { +LuaScriptingCallContext::LuaScriptingCallContext() : mReturnValue(0) +{ +} +LuaScriptingCallContext::~LuaScriptingCallContext() +{ + delete mReturnValue; } + } diff --git a/src/components/ogre/scripting/LuaScriptingCallContext.h b/src/components/ogre/scripting/LuaScriptingCallContext.h new file mode 100644 index 0000000..8a4b2d1 --- /dev/null +++ b/src/components/ogre/scripting/LuaScriptingCallContext.h @@ -0,0 +1,73 @@ +// +// C++ Interface: LuaScriptingCallContext +// +// Description: +// +// +// Author: Erik Hjortsberg , (C) 2008 +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.// +// +#ifndef EMBEROGRELUASCRIPTINGCALLCONTEXT_H +#define EMBEROGRELUASCRIPTINGCALLCONTEXT_H + +#include "luaobject.h" +#include "framework/IScriptingProvider.h" + +namespace EmberOgre { + +/** + at brief A scripting call context for lua scripts. +Whenever you want to be able to inspect return values from calling lua scripts, you should use an instance of this class and submit it when calling executeCode(...). + @author Erik Hjortsberg +*/ +class LuaScriptingCallContext : public Ember::IScriptingCallContext +{ +friend class LuaScriptingProvider; +public: + LuaScriptingCallContext(); + virtual ~LuaScriptingCallContext(); + /** + * Gets the return value of the lua call. + * @return + */ + inline LuaRef* getReturnValue(); +protected: + /** + * Sets the return value of the lua call. This is an internal method used only by the lua scripting provider. + * @param returnValue + */ + inline void setReturnValue(LuaRef* returnValue); + + /** + The return value from the lua call. + */ + LuaRef* mReturnValue; +}; + +void LuaScriptingCallContext::setReturnValue(LuaRef* returnValue) +{ + delete returnValue; + mReturnValue = returnValue; +} + +LuaRef* LuaScriptingCallContext::getReturnValue() +{ + return mReturnValue; +} + +} + +#endif diff --git a/src/components/ogre/scripting/LuaScriptingProvider.cpp b/src/components/ogre/scripting/LuaScriptingProvider.cpp index 03617d8..f902905 100644 --- a/src/components/ogre/scripting/LuaScriptingProvider.cpp +++ b/src/components/ogre/scripting/LuaScriptingProvider.cpp @@ -44,6 +44,7 @@ extern "C" { //#include #include #include "LuaHelper.h" +#include "LuaScriptingCallContext.h" TOLUA_API int tolua_Ogre_open (lua_State* tolua_S); TOLUA_API int tolua_Eris_open (lua_State* tolua_S); @@ -323,13 +324,6 @@ void LuaScriptingProvider::forceGC() // } -LuaScriptingCallContext::LuaScriptingCallContext() : mReturnValue(0) -{ -} -LuaScriptingCallContext::~LuaScriptingCallContext() -{ - delete mReturnValue; -} } diff --git a/src/components/ogre/scripting/LuaScriptingProvider.h b/src/components/ogre/scripting/LuaScriptingProvider.h index f31b255..ded567f 100644 --- a/src/components/ogre/scripting/LuaScriptingProvider.h +++ b/src/components/ogre/scripting/LuaScriptingProvider.h @@ -28,7 +28,6 @@ #include #include -#include "luaobject.h" struct lua_State; @@ -39,28 +38,7 @@ namespace Ember namespace EmberOgre { -class LuaScriptingCallContext : public Ember::IScriptingCallContext -{ -public: - inline LuaScriptingCallContext(); - inline ~LuaScriptingCallContext(); - inline void setReturnValue(LuaRef* returnValue); - inline LuaRef* getReturnValue(); -protected: - LuaRef* mReturnValue; -}; - -void LuaScriptingCallContext::setReturnValue(LuaRef* returnValue) -{ - delete returnValue; - mReturnValue = returnValue; -} - -LuaRef* LuaScriptingCallContext::getReturnValue() -{ - return mReturnValue; -} - +class LuaScriptingCallContext; /** @brief A scripting provider for Lua. diff --git a/src/components/ogre/scripting/Makefile.am b/src/components/ogre/scripting/Makefile.am index 5e20cf0..d647cb4 100644 --- a/src/components/ogre/scripting/Makefile.am +++ b/src/components/ogre/scripting/Makefile.am @@ -1,6 +1,6 @@ INCLUDES = -I$(top_srcdir)/src -I$(top_builddir)/src -DPREFIX=\"@prefix@\" SUBDIRS = bindings noinst_LTLIBRARIES = libScripting.la -libScripting_la_SOURCES = LuaHelper.cpp LuaScriptingProvider.cpp luaobject.cpp -noinst_HEADERS = LuaHelper.h LuaScriptingProvider.h luaobject.h +libScripting_la_SOURCES = LuaHelper.cpp LuaScriptingProvider.cpp luaobject.cpp LuaScriptingCallContext.cpp +noinst_HEADERS = LuaHelper.h LuaScriptingProvider.h luaobject.h LuaScriptingCallContext.h -- The Ember WorldForge client. From commitmsg at worldforge.de Thu Jun 5 15:17:23 2008 From: commitmsg at worldforge.de (commitmsg at worldforge.de) Date: Fri, 6 Jun 2008 00:17:23 +0200 (CEST) Subject: [WF-CVS] [WF-git] The Ember WorldForge client. branch, lua_return_values, updated. effb28e22d80320e36622db628ea7bc224f98082 Message-ID: <20080605221725.44C73184A0462@worldforge.de> The branch, lua_return_values has been updated via effb28e22d80320e36622db628ea7bc224f98082 (commit) from 1e6e518ec55824e0ef64dd80ca84c36ff6769017 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit effb28e22d80320e36622db628ea7bc224f98082 Author: Erik Hjortsberg Date: Fri Jun 6 00:17:05 2008 +0200 Better docs. ----------------------------------------------------------------------- Summary of changes: .../ogre/scripting/LuaScriptingProvider.h | 37 ++++++++++++++----- src/framework/IScriptingProvider.h | 29 +++++++++++----- 2 files changed, 47 insertions(+), 19 deletions(-) Changeset truncated at 500 lines: diff --git a/src/components/ogre/scripting/LuaScriptingProvider.h b/src/components/ogre/scripting/LuaScriptingProvider.h index ded567f..ebe0873 100644 --- a/src/components/ogre/scripting/LuaScriptingProvider.h +++ b/src/components/ogre/scripting/LuaScriptingProvider.h @@ -43,9 +43,9 @@ class LuaScriptingCallContext; /** @brief A scripting provider for Lua. -This acts as a bridge between Ember and the Lua scripting environment. Opon creation and destruction it will take care of setting up and tearing down the lua virtual machine. Remember to call @see stop() before deleting an instance of this to make sure that everyting is properly cleaned up. +This acts as a bridge between Ember and the Lua scripting environment. Opon creation and destruction it will take care of setting up and tearing down the lua virtual machine. Remember to call stop() before deleting an instance of this to make sure that everything is properly cleaned up. -If you want to inspect the return values from calls to lua scripts, pass a pointer to @see LuaScriptingCallContext to the executeScript methods. +If you want to inspect the return values from calls to lua scripts, pass a pointer to LuaScriptingCallContext to the executeScript methods. @author Erik Hjortsberg */ class LuaScriptingProvider : public Ember::IScriptingProvider @@ -70,26 +70,26 @@ public: virtual void executeScript(const std::string& scriptCode, Ember::IScriptingCallContext* callContext); /** - * @brief Returns true if the provider will load the supplied script name. This is in most cases decided from the filename suffix. - * @param scriptName - * @return + * @brief Returns true if the provider will load the supplied script name. This is in most cases decided from the filename suffix. + * @param scriptName The name of the script. + * @return True if the script can be loaded, else false. */ virtual bool willLoadScript(const std::string& scriptName); /** - * @brief Gets the unique name of the scripting provider. - * @return + * @brief Gets the unique name of the scripting provider. + * @return The name of the scripting provider. */ virtual const std::string& getName() const; /** - * @brief Register with a service to allow for callbacks etc. - * @param service + * @brief Register with a service to allow for callbacks etc. + * @param service The service to register with. */ virtual void _registerWithService(Ember::ScriptingService* service); /** - * @brief Forces a full garbage collection. + * @brief Forces a full garbage collection. */ virtual void forceGC(); @@ -121,10 +121,27 @@ private: */ void executeScriptImpl(const std::string& scriptCode, LuaScriptingCallContext* luaCallContext, const std::string& scriptName = std::string("")); + /** + * Initializes the lua scripting environment. This entails creating a new Lua virtual machine/state, making sure that the correct lua libraries are loaded and a calling tolua bindings registering hooks. + If you add a new tolua bindings class, don't forget to alter this method to include a call to the method which registers all classes and structs. + */ void initialize(); + + + /** + * Creates a new Lua virtual machine/state. + */ void createState(); // std::auto_ptr mLuaScriptModule; + + /** + The main scripting service instance. + */ Ember::ScriptingService* mService; + + /** + The main lua state. This is the sole entry into the lua virtual machine. + */ lua_State* mLuaState; }; diff --git a/src/framework/IScriptingProvider.h b/src/framework/IScriptingProvider.h index 7382e8a..12cb878 100644 --- a/src/framework/IScriptingProvider.h +++ b/src/framework/IScriptingProvider.h @@ -43,6 +43,14 @@ class ScriptingService; // protected: // }; + +/** + at brief Base interface for a call into a scripting environment. +Sometimes when you make a call into a scripting environment, from the C++ code, you want to be able to inspect and act upon the return values. However, different scripting languages handles these things differently, so instead of a common class we provide this very bare bone interface. It's then up to to each implementation of IScriptingProvider to make sure that it also provides a concrete implementation of this class and knows how to handle it. + +Whenever you then want to act on values returned from a call into a specific scripting environment you have to first create the suitable instance of a subclass of this, and then pass that onto a call to the ScriptingService::executeScript method. + at author Erik Hjortsberg +*/ class IScriptingCallContext { public: @@ -53,16 +61,19 @@ protected: }; /** - at author Erik Hjortsberg + at brief A generic scripting provider. +We want to support many different scripting environments, so the ScriptingService isn't bound to any one type and insteads deals with abstract implementations of this interface. Any implementation is then bound to a specific scripting environment, such as Lua or Python. + +Any implementation of this interface is expected to handle setup and teardown of the underlying scripting environment/virtual machine. +Often you want to do it in two separate steps, where a call to stop() forces the scripting environment to unload all allocated objects and structs, and the desctructor then handles destroying the scripting environment completely. + at author Erik Hjortsberg */ -class IScriptingProvider{ +class IScriptingProvider +{ public: virtual ~IScriptingProvider(){} -// virtual IScriptingCallContext createDefaultContext() = 0; - - /** * @brief Loads the script from the wrapper. * @param resourceWrapper A resource wrapper pointing to a valid resource which can be loaded. This should contain a text file with the script contents. @@ -80,20 +91,20 @@ public: /** * @brief Returns true if the provider will load the supplied script name. This is in most cases decided from the filename suffix. - * @param scriptName - * @return + * @param scriptName The name of the script. + * @return True if the script can be loaded, else false. */ virtual bool willLoadScript(const std::string& scriptName) = 0; /** * @brief Gets the unique name of the scripting provider. - * @return + * @return The name of the scripting provider. */ virtual const std::string& getName() const = 0; /** * @brief Register with a service to allow for callbacks etc. - * @param service + * @param service The service to register with. */ virtual void _registerWithService(ScriptingService* service) = 0; -- The Ember WorldForge client. From commitmsg at worldforge.de Thu Jun 5 15:40:11 2008 From: commitmsg at worldforge.de (commitmsg at worldforge.de) Date: Fri, 6 Jun 2008 00:40:11 +0200 (CEST) Subject: [WF-CVS] [WF-git] The Ember WorldForge client. branch, master, updated. b5da7d2711ce574a16a7faa36afccea8c76b11f3 Message-ID: <20080605224016.C77B32977801E@worldforge.de> The branch, master has been updated via b5da7d2711ce574a16a7faa36afccea8c76b11f3 (commit) via 3db8f1825a3f670e439c1ffeb4d7f54275777398 (commit) via 92f7c10b5011f0b9c7619087f0957f04445ccd28 (commit) via 84b25bac60cd76ad0b4d9f306d61bd0fe024f404 (commit) via 17c8c2b0fba3c67882a2339f17a7a9672897fa75 (commit) via 94aeaa9338fd3e0e00963e886cd07dcfe3729c47 (commit) via be92b58254c90f8a6600754aa40a987fa5906a31 (commit) via 793e1a670fb7ccc1fba268d3462b0659052f0f5c (commit) via 48393899af4a87469cd0e48bb12f8089b15d0ea5 (commit) via 85f59c214e7e6ae95dcaf5714a1ce0e36d23c2c3 (commit) via d67d7b416c501216a1eb9974fa2828fe90226ea1 (commit) from 2af9a5994ad9806867d88cf30c86d09448465921 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit b5da7d2711ce574a16a7faa36afccea8c76b11f3 Author: Erik Hjortsberg Date: Fri Jun 6 00:17:05 2008 +0200 Better docs. commit 3db8f1825a3f670e439c1ffeb4d7f54275777398 Author: Erik Hjortsberg Date: Thu Jun 5 22:44:42 2008 +0200 Moved the lua scripting call context to its own file. commit 92f7c10b5011f0b9c7619087f0957f04445ccd28 Author: Erik Hjortsberg Date: Thu Jun 5 22:11:10 2008 +0200 Cleaned up the api a little bit. Since the context is optional we want to put that as the last parameter. commit 84b25bac60cd76ad0b4d9f306d61bd0fe024f404 Author: Erik Hjortsberg Date: Thu Jun 5 21:15:09 2008 +0200 Moved the constructor and destructor to .cpp file to fix linking errors. Also added more comments and made it use the sent in context when executing scripts. commit 17c8c2b0fba3c67882a2339f17a7a9672897fa75 Author: Alexey Torkhov Date: Thu Jun 5 20:56:04 2008 +0400 Make it compilable. commit 94aeaa9338fd3e0e00963e886cd07dcfe3729c47 Author: Alexey Torkhov Date: Wed Jun 4 10:18:06 2008 +0400 Passing call context as a pointer instead of reference. Removing duplicate code. commit be92b58254c90f8a6600754aa40a987fa5906a31 Author: Alexey Torkhov Date: Mon Jun 2 21:02:08 2008 +0400 No need to check for NULL pointer before delete. Clean up to conform with coding standards. commit 793e1a670fb7ccc1fba268d3462b0659052f0f5c Author: Alexey Torkhov Date: Mon Jun 2 16:28:46 2008 +0400 Dereferencing objects to prevent memory leaking. But this should be done in more rebust way. commit 48393899af4a87469cd0e48bb12f8089b15d0ea5 Author: Erik Hjortsberg Date: Sun Jun 1 21:17:57 2008 +0200 Fixed some problems with how script return values were handled. commit 85f59c214e7e6ae95dcaf5714a1ce0e36d23c2c3 Author: Erik Hjortsberg Date: Sun Jun 1 14:27:38 2008 +0200 Added the ability to get return values from script calls through the use of a script call context object. commit d67d7b416c501216a1eb9974fa2828fe90226ea1 Author: Erik Hjortsberg Date: Sun Jun 1 14:26:40 2008 +0200 Added helper classes for handling lua return types in c++ code. ----------------------------------------------------------------------- Summary of changes: .../ogre/scripting/LuaScriptingCallContext.cpp} | 15 +- .../ogre/scripting/LuaScriptingCallContext.h | 73 +++ .../ogre/scripting/LuaScriptingProvider.cpp | 119 ++-- .../ogre/scripting/LuaScriptingProvider.h | 80 ++- src/components/ogre/scripting/Makefile.am | 4 +- src/components/ogre/scripting/luaobject.cpp | 61 ++ src/components/ogre/scripting/luaobject.h | 581 ++++++++++++++++++++ src/framework/IScriptingProvider.h | 72 ++- src/framework/bindings/lua/Framework.pkg | 2 +- src/framework/bindings/lua/lua_Framework.cpp | 146 +----- src/services/scripting/ScriptingService.cpp | 4 +- src/services/scripting/ScriptingService.h | 5 +- 12 files changed, 909 insertions(+), 253 deletions(-) copy src/{services/logging/Observer.cpp => components/ogre/scripting/LuaScriptingCallContext.cpp} (77%) create mode 100644 src/components/ogre/scripting/LuaScriptingCallContext.h create mode 100644 src/components/ogre/scripting/luaobject.cpp create mode 100644 src/components/ogre/scripting/luaobject.h Changeset truncated at 500 lines: diff --git a/src/services/logging/Observer.cpp b/src/components/ogre/scripting/LuaScriptingCallContext.cpp similarity index 77% copy from src/services/logging/Observer.cpp copy to src/components/ogre/scripting/LuaScriptingCallContext.cpp index 0c72340..6217d29 100644 --- a/src/services/logging/Observer.cpp +++ b/src/components/ogre/scripting/LuaScriptingCallContext.cpp @@ -1,5 +1,5 @@ // -// C++ Implementation: Observer +// C++ Implementation: LuaScriptingCallContext // // Description: // @@ -24,13 +24,18 @@ #include "config.h" #endif -#include "Observer.h" +#include "LuaScriptingCallContext.h" -namespace Ember { - -namespace LogginService { +namespace EmberOgre { +LuaScriptingCallContext::LuaScriptingCallContext() : mReturnValue(0) +{ +} +LuaScriptingCallContext::~LuaScriptingCallContext() +{ + delete mReturnValue; } + } diff --git a/src/components/ogre/scripting/LuaScriptingCallContext.h b/src/components/ogre/scripting/LuaScriptingCallContext.h new file mode 100644 index 0000000..8a4b2d1 --- /dev/null +++ b/src/components/ogre/scripting/LuaScriptingCallContext.h @@ -0,0 +1,73 @@ +// +// C++ Interface: LuaScriptingCallContext +// +// Description: +// +// +// Author: Erik Hjortsberg , (C) 2008 +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.// +// +#ifndef EMBEROGRELUASCRIPTINGCALLCONTEXT_H +#define EMBEROGRELUASCRIPTINGCALLCONTEXT_H + +#include "luaobject.h" +#include "framework/IScriptingProvider.h" + +namespace EmberOgre { + +/** + at brief A scripting call context for lua scripts. +Whenever you want to be able to inspect return values from calling lua scripts, you should use an instance of this class and submit it when calling executeCode(...). + @author Erik Hjortsberg +*/ +class LuaScriptingCallContext : public Ember::IScriptingCallContext +{ +friend class LuaScriptingProvider; +public: + LuaScriptingCallContext(); + virtual ~LuaScriptingCallContext(); + /** + * Gets the return value of the lua call. + * @return + */ + inline LuaRef* getReturnValue(); +protected: + /** + * Sets the return value of the lua call. This is an internal method used only by the lua scripting provider. + * @param returnValue + */ + inline void setReturnValue(LuaRef* returnValue); + + /** + The return value from the lua call. + */ + LuaRef* mReturnValue; +}; + +void LuaScriptingCallContext::setReturnValue(LuaRef* returnValue) +{ + delete returnValue; + mReturnValue = returnValue; +} + +LuaRef* LuaScriptingCallContext::getReturnValue() +{ + return mReturnValue; +} + +} + +#endif diff --git a/src/components/ogre/scripting/LuaScriptingProvider.cpp b/src/components/ogre/scripting/LuaScriptingProvider.cpp index e35f494..f902905 100644 --- a/src/components/ogre/scripting/LuaScriptingProvider.cpp +++ b/src/components/ogre/scripting/LuaScriptingProvider.cpp @@ -44,6 +44,7 @@ extern "C" { //#include #include #include "LuaHelper.h" +#include "LuaScriptingCallContext.h" TOLUA_API int tolua_Ogre_open (lua_State* tolua_S); TOLUA_API int tolua_Eris_open (lua_State* tolua_S); @@ -79,7 +80,9 @@ void LuaScriptingProvider::stop() try { ///we want to clear up the lua environment without destroying it (lua_close destroys it) std::string shutdownScript("for key,value in pairs(_G) do if key ~= \"_G\" and key ~= \"pairs\" then _G[key] = nil end end"); - executeScript(shutdownScript); + { + executeScript(shutdownScript, 0); + } forceGC(); } catch (...) { S_LOG_WARNING("Error when stopping lua."); @@ -167,19 +170,35 @@ lua_State* LuaScriptingProvider::getLuaState() void LuaScriptingProvider::loadScript(Ember::ResourceWrapper& resWrapper) { + executeScriptImpl(std::string(resWrapper.getDataPtr(), resWrapper.getSize()), 0, resWrapper.getName()); +} + +void LuaScriptingProvider::executeScript(const std::string& scriptCode, Ember::IScriptingCallContext* callContext) +{ + + executeScriptImpl(scriptCode, static_cast(callContext), ""); +} + +void LuaScriptingProvider::executeScriptImpl(const std::string& scriptCode, LuaScriptingCallContext* luaCallContext, const std::string& scriptName) +{ try { - - // load code into lua int top = lua_gettop(mLuaState); - int loaderr = luaL_loadbuffer(mLuaState, resWrapper.getDataPtr(), resWrapper.getSize(), resWrapper.getName().c_str()); - + int loaderr = luaL_loadbuffer(mLuaState, scriptCode.c_str(), scriptCode.length(), scriptCode.c_str()); + if (loaderr) { std::string errMsg(lua_tostring(mLuaState,-1)); lua_settop(mLuaState,top); - throw Ember::Exception("Unable to load Lua script file: '"+resWrapper.getName()+"'\n\n"+errMsg+"\n"); + if (!scriptName.empty()) + { + throw Ember::Exception("Unable to load Lua script file: '"+scriptName+"'\n\n"+errMsg+"\n"); + } + else + { + throw Ember::Exception("Unable to load Lua script: '" + scriptCode + "'\n\n"+errMsg+"\n"); + } } - + ///push our error handling method before calling the code int error_index = lua_gettop(mLuaState); #if LUA51 @@ -188,78 +207,56 @@ void LuaScriptingProvider::loadScript(Ember::ResourceWrapper& resWrapper) lua_pushliteral(mLuaState, "_TRACEBACK"); lua_rawget(mLuaState, LUA_GLOBALSINDEX); /* get traceback function */ #endif - lua_insert(mLuaState, error_index);/* put it under chunk and args */ - + lua_insert(mLuaState, error_index); - // call it - if (lua_pcall(mLuaState,0,0,error_index)) + /// load code into lua and call it + int error, nresults; + int level = lua_gettop(mLuaState); // top of stack position + // if we have context to store return values, then get them + if (luaCallContext) { - std::string errMsg(lua_tostring(mLuaState,-1)); - lua_settop(mLuaState,top); - throw Ember::Exception("Unable to execute Lua script file: '"+resWrapper.getName()+"'\n\n"+errMsg+"\n"); + error = lua_pcall(mLuaState, 0, LUA_MULTRET, error_index); + nresults = lua_gettop(mLuaState) - level; // number of results } - - lua_settop(mLuaState,top); // just in case :P - - -// getScriptModule().executeScriptFile(scriptName); - } catch (const CEGUI::Exception& ex) { - throw Ember::Exception(ex.getMessage().c_str()); - } catch( const CEGUI::String& str ) - { - throw Ember::Exception(str.c_str()); - } catch (const Ember::Exception& ex) { - throw ex; - } catch (...) { - throw Ember::Exception("Unknown error."); - } -/* } catch (const Ogre::Exception& ex) { - throw Ember::Exception("Error when loading script " + scriptName + ". Message: " + ex.get); - }*/ -} - -void LuaScriptingProvider::executeScript(const std::string& scriptCode) -{ - try { - int top = lua_gettop(mLuaState); - - - int loaderr = luaL_loadbuffer(mLuaState, scriptCode.c_str(), scriptCode.length(), scriptCode.c_str()); - - if (loaderr) + else { - std::string errMsg(lua_tostring(mLuaState,-1)); - lua_settop(mLuaState,top); - throw Ember::Exception("Unable to load Lua script: '" + scriptCode + "'\n\n"+errMsg+"\n"); + error = lua_pcall(mLuaState, 0, 0, error_index); } - - ///push our error handling method before calling the code - int error_index = lua_gettop(mLuaState); - lua_pushcfunction(mLuaState, ::EmberOgre::Scripting::LuaHelper::luaErrorHandler); - lua_insert(mLuaState, error_index); - - /// load code into lua and call it - int error = lua_pcall(mLuaState,0,0,error_index); - + // handle errors if (error) { std::string errMsg(lua_tostring(mLuaState,-1)); lua_settop(mLuaState,top); - throw Ember::Exception("Unable to execute Lua script string: '"+scriptCode+"'\n\n"+errMsg+"\n"); + if (!scriptName.empty()) + { + throw Ember::Exception("Unable to load Lua script file: '"+scriptName+"'\n\n"+errMsg+"\n"); + } + else + { + throw Ember::Exception("Unable to load Lua script: '" + scriptCode + "'\n\n"+errMsg+"\n"); + } } + + if (luaCallContext) + { + fromStack fs(mLuaState); + LuaRef* luaRef = new LuaRef(fs); + luaCallContext->setReturnValue(luaRef); + } + + lua_settop(mLuaState,top); // just in case :P - do we need it? + // getScriptModule().executeString(scriptCode); } catch (const CEGUI::Exception& ex) { throw Ember::Exception(ex.getMessage().c_str()); - } catch( const CEGUI::String& str ) - { + } catch( const CEGUI::String& str ) { throw Ember::Exception(str.c_str()); } catch (const Ember::Exception& ex) { throw ex; } catch (...) { throw Ember::Exception("Unknown error."); } - } bool LuaScriptingProvider::willLoadScript(const std::string& scriptName) @@ -281,6 +278,7 @@ void LuaScriptingProvider::_registerWithService(Ember::ScriptingService* service mService = service; } + void LuaScriptingProvider::forceGC() { #ifdef LUA51 @@ -325,4 +323,7 @@ void LuaScriptingProvider::forceGC() // return mLuaScriptModule; // } + + + } diff --git a/src/components/ogre/scripting/LuaScriptingProvider.h b/src/components/ogre/scripting/LuaScriptingProvider.h index ffe7098..ebe0873 100644 --- a/src/components/ogre/scripting/LuaScriptingProvider.h +++ b/src/components/ogre/scripting/LuaScriptingProvider.h @@ -28,6 +28,7 @@ #include #include + struct lua_State; namespace Ember @@ -37,7 +38,14 @@ namespace Ember namespace EmberOgre { +class LuaScriptingCallContext; + /** + at brief A scripting provider for Lua. + +This acts as a bridge between Ember and the Lua scripting environment. Opon creation and destruction it will take care of setting up and tearing down the lua virtual machine. Remember to call stop() before deleting an instance of this to make sure that everything is properly cleaned up. + +If you want to inspect the return values from calls to lua scripts, pass a pointer to LuaScriptingCallContext to the executeScript methods. @author Erik Hjortsberg */ class LuaScriptingProvider : public Ember::IScriptingProvider @@ -46,62 +54,94 @@ public: LuaScriptingProvider(); virtual ~LuaScriptingProvider(); - + /** - * Loads the script. - * @param scriptName + * @brief Loads the script from the wrapper. + * @param resourceWrapper A resource wrapper pointing to a valid resource which can be loaded. This should contain a text file with the script contents. */ virtual void loadScript(Ember::ResourceWrapper& resWrapper); /** - * Executes the supplied string directly into the scripting environment. - * @param scriptCode + * @brief Executes the supplied string directly into the scripting environment. + * Optionally a pointer to a scripting call context can be submitted too, which will then be populated with return values and other scripting environment specific info. + * @param scriptCode The code to excute. + * @param callContext An optional pointer to a scripting call context. This will be populated with return values and other info. If you don't have any need for such info, leave this empty. */ - virtual void executeScript(const std::string& scriptCode); + virtual void executeScript(const std::string& scriptCode, Ember::IScriptingCallContext* callContext); /** - * Returns true if the provider will load the supplied script name. This is in most cases decided from the filename suffix. - * @param scriptName - * @return + * @brief Returns true if the provider will load the supplied script name. This is in most cases decided from the filename suffix. + * @param scriptName The name of the script. + * @return True if the script can be loaded, else false. */ virtual bool willLoadScript(const std::string& scriptName); /** - * Gets the unique name of the scripting provider. - * @return + * @brief Gets the unique name of the scripting provider. + * @return The name of the scripting provider. */ virtual const std::string& getName() const; /** - * Register with a service to allow for callbacks etc. - * @param service + * @brief Register with a service to allow for callbacks etc. + * @param service The service to register with. */ virtual void _registerWithService(Ember::ScriptingService* service); /** - * Forces a full garbage collection. + * @brief Forces a full garbage collection. */ virtual void forceGC(); // virtual void start(); + + + /** + * @brief Stops the lua environment, which mainly means that all objects are destroyed. + * Call this before this object is destroyed to make sure that all held objects and references are properly released. If not, there's a risk of dangling pointers. + */ virtual void stop(); - /** - * Returns the scripting module - * @return - */ -// CEGUI::ScriptModule& getScriptModule(); - + /** + * @brief Gets the current lua state. + * This will always return a valid lua virtual machine, but note that if @see stop() already has been called it will porbably be in an invalid state. + * @return The current lua environment. + */ lua_State* getLuaState(); private: + /** + * @brief Executes the supplied script code. + * @param scriptCode The code to execute. + * @param luaCallContext An optional lua call context, which if present will contain any return values. + * @param scriptName The name of the script, mainly used for debugging purpose. + */ + void executeScriptImpl(const std::string& scriptCode, LuaScriptingCallContext* luaCallContext, const std::string& scriptName = std::string("")); + + /** + * Initializes the lua scripting environment. This entails creating a new Lua virtual machine/state, making sure that the correct lua libraries are loaded and a calling tolua bindings registering hooks. + If you add a new tolua bindings class, don't forget to alter this method to include a call to the method which registers all classes and structs. + */ void initialize(); + + + /** + * Creates a new Lua virtual machine/state. + */ void createState(); // std::auto_ptr mLuaScriptModule; + + /** + The main scripting service instance. + */ Ember::ScriptingService* mService; + + /** + The main lua state. This is the sole entry into the lua virtual machine. + */ lua_State* mLuaState; }; diff --git a/src/components/ogre/scripting/Makefile.am b/src/components/ogre/scripting/Makefile.am index 6f286d7..d647cb4 100644 --- a/src/components/ogre/scripting/Makefile.am +++ b/src/components/ogre/scripting/Makefile.am @@ -1,6 +1,6 @@ INCLUDES = -I$(top_srcdir)/src -I$(top_builddir)/src -DPREFIX=\"@prefix@\" SUBDIRS = bindings noinst_LTLIBRARIES = libScripting.la -libScripting_la_SOURCES = LuaHelper.cpp LuaScriptingProvider.cpp -noinst_HEADERS = LuaHelper.h LuaScriptingProvider.h +libScripting_la_SOURCES = LuaHelper.cpp LuaScriptingProvider.cpp luaobject.cpp LuaScriptingCallContext.cpp +noinst_HEADERS = LuaHelper.h LuaScriptingProvider.h luaobject.h LuaScriptingCallContext.h diff --git a/src/components/ogre/scripting/luaobject.cpp b/src/components/ogre/scripting/luaobject.cpp new file mode 100644 index 0000000..ab16492 --- /dev/null +++ b/src/components/ogre/scripting/luaobject.cpp @@ -0,0 +1,61 @@ +// luaobject.h +// +// Copyright 2008 by Nigel Atkinson suprapilot+LuaCode at gmail.com +// +// This library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// A copy of theGNU General Public License is availible at: +// . +// +// Makes interfacing with Lua easier. +// Tested with Lua 5.1.3 and 5.1.2. +// MSVC 7.12 (2003) and GCC (g++) 4.1.2 + +// 8th May 2008 Nigel +// Added LuaException class and changed all throws to use it. User code can use it too. +// It grabs any string, if any, from the top of the Lua stack. + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "luaobject.h" + +void LuaVal::push( lua_State *L ) -- The Ember WorldForge client. From commitmsg at worldforge.de Fri Jun 6 00:38:37 2008 From: commitmsg at worldforge.de (commitmsg at worldforge.de) Date: Fri, 6 Jun 2008 09:38:37 +0200 (CEST) Subject: [WF-CVS] [WF-git] Alex' GSoC-2008 project branch, entity_creator, updated. 26c2cfbee372804770bfb37d93e3323e14ed3eb6 Message-ID: <20080606073847.7BF132977801E@worldforge.de> The branch, entity_creator has been updated via 26c2cfbee372804770bfb37d93e3323e14ed3eb6 (commit) via 8500a495adc08089200b0de49063e03c176759c9 (commit) via 44840e881287ccb1ac78d0b633351e270216c08a (commit) via dcc4192c19d0813970912de91226bb228e264c8a (commit) via abd6ff30a12775d78a4e814bf41b7803aef72735 (commit) via 6e33642602c1ce32f0b02fe67c657d8e7ad9abd2 (commit) via 40253b1524c5a33f2eab6eb957b4a27fc73a526d (commit) via 19f5c8dcadc635548f223835aae59d8f925e92ed (commit) via 2413654b0914568d108f6acf1e2d0e40dfdb0422 (commit) via b98723757c7cbf293c228473b3b46c00e55f638d (commit) via 9e0955c547c58dcdbdb6f9d47931886c97104d3e (commit) from bac32ad53429887d3856fce17fd120b17156cf85 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 26c2cfbee372804770bfb37d93e3323e14ed3eb6 Author: Erik Hjortsberg Date: Fri Jun 6 00:17:05 2008 +0200 Better docs. commit 8500a495adc08089200b0de49063e03c176759c9 Author: Erik Hjortsberg Date: Thu Jun 5 22:44:42 2008 +0200 Moved the lua scripting call context to its own file. commit 44840e881287ccb1ac78d0b633351e270216c08a Author: Erik Hjortsberg Date: Thu Jun 5 22:11:10 2008 +0200 Cleaned up the api a little bit. Since the context is optional we want to put that as the last parameter. commit dcc4192c19d0813970912de91226bb228e264c8a Author: Erik Hjortsberg Date: Thu Jun 5 21:15:09 2008 +0200 Moved the constructor and destructor to .cpp file to fix linking errors. Also added more comments and made it use the sent in context when executing scripts. commit abd6ff30a12775d78a4e814bf41b7803aef72735 Author: Alexey Torkhov Date: Thu Jun 5 20:56:04 2008 +0400 Make it compilable. commit 6e33642602c1ce32f0b02fe67c657d8e7ad9abd2 Author: Alexey Torkhov Date: Wed Jun 4 10:18:06 2008 +0400 Passing call context as a pointer instead of reference. Removing duplicate code. commit 40253b1524c5a33f2eab6eb957b4a27fc73a526d Author: Alexey Torkhov Date: Mon Jun 2 21:02:08 2008 +0400 No need to check for NULL pointer before delete. Clean up to conform with coding standards. commit 19f5c8dcadc635548f223835aae59d8f925e92ed Author: Alexey Torkhov Date: Mon Jun 2 16:28:46 2008 +0400 Dereferencing objects to prevent memory leaking. But this should be done in more rebust way. commit 2413654b0914568d108f6acf1e2d0e40dfdb0422 Author: Erik Hjortsberg Date: Sun Jun 1 21:17:57 2008 +0200 Fixed some problems with how script return values were handled. commit b98723757c7cbf293c228473b3b46c00e55f638d Author: Erik Hjortsberg Date: Sun Jun 1 14:27:38 2008 +0200 Added the ability to get return values from script calls through the use of a script call context object. commit 9e0955c547c58dcdbdb6f9d47931886c97104d3e Author: Erik Hjortsberg Date: Sun Jun 1 14:26:40 2008 +0200 Added helper classes for handling lua return types in c++ code. ----------------------------------------------------------------------- Summary of changes: .../LuaScriptingCallContext.cpp} | 16 +- .../ogre/scripting/LuaScriptingCallContext.h | 73 +++ .../ogre/scripting/LuaScriptingProvider.cpp | 119 ++-- .../ogre/scripting/LuaScriptingProvider.h | 80 ++- src/components/ogre/scripting/Makefile.am | 4 +- src/components/ogre/scripting/luaobject.cpp | 61 ++ src/components/ogre/scripting/luaobject.h | 581 ++++++++++++++++++++ src/framework/IScriptingProvider.h | 72 ++- src/framework/bindings/lua/Framework.pkg | 2 +- src/framework/bindings/lua/lua_Framework.cpp | 146 +----- src/services/scripting/ScriptingService.cpp | 4 +- src/services/scripting/ScriptingService.h | 5 +- 12 files changed, 906 insertions(+), 257 deletions(-) copy src/components/ogre/{manipulation/GUIAdapter.cpp => scripting/LuaScriptingCallContext.cpp} (73%) create mode 100644 src/components/ogre/scripting/LuaScriptingCallContext.h create mode 100644 src/components/ogre/scripting/luaobject.cpp create mode 100644 src/components/ogre/scripting/luaobject.h Changeset truncated at 500 lines: diff --git a/src/components/ogre/manipulation/GUIAdapter.cpp b/src/components/ogre/scripting/LuaScriptingCallContext.cpp similarity index 73% copy from src/components/ogre/manipulation/GUIAdapter.cpp copy to src/components/ogre/scripting/LuaScriptingCallContext.cpp index 612ee4f..6217d29 100644 --- a/src/components/ogre/manipulation/GUIAdapter.cpp +++ b/src/components/ogre/scripting/LuaScriptingCallContext.cpp @@ -1,10 +1,10 @@ // -// C++ Implementation: GuiAdapter +// C++ Implementation: LuaScriptingCallContext // // Description: // // -// Author: Alexey Torkhov , (C) 2008 +// Author: Erik Hjortsberg , (C) 2008 // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -20,24 +20,22 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.// // - #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include "GUIAdapter.h" +#include "LuaScriptingCallContext.h" namespace EmberOgre { -GUIAdapter::GUIAdapter(std::string type) : - mType(type) +LuaScriptingCallContext::LuaScriptingCallContext() : mReturnValue(0) { - } -GUIAdapter::~GUIAdapter() +LuaScriptingCallContext::~LuaScriptingCallContext() { - + delete mReturnValue; } + } diff --git a/src/components/ogre/scripting/LuaScriptingCallContext.h b/src/components/ogre/scripting/LuaScriptingCallContext.h new file mode 100644 index 0000000..8a4b2d1 --- /dev/null +++ b/src/components/ogre/scripting/LuaScriptingCallContext.h @@ -0,0 +1,73 @@ +// +// C++ Interface: LuaScriptingCallContext +// +// Description: +// +// +// Author: Erik Hjortsberg , (C) 2008 +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.// +// +#ifndef EMBEROGRELUASCRIPTINGCALLCONTEXT_H +#define EMBEROGRELUASCRIPTINGCALLCONTEXT_H + +#include "luaobject.h" +#include "framework/IScriptingProvider.h" + +namespace EmberOgre { + +/** + at brief A scripting call context for lua scripts. +Whenever you want to be able to inspect return values from calling lua scripts, you should use an instance of this class and submit it when calling executeCode(...). + @author Erik Hjortsberg +*/ +class LuaScriptingCallContext : public Ember::IScriptingCallContext +{ +friend class LuaScriptingProvider; +public: + LuaScriptingCallContext(); + virtual ~LuaScriptingCallContext(); + /** + * Gets the return value of the lua call. + * @return + */ + inline LuaRef* getReturnValue(); +protected: + /** + * Sets the return value of the lua call. This is an internal method used only by the lua scripting provider. + * @param returnValue + */ + inline void setReturnValue(LuaRef* returnValue); + + /** + The return value from the lua call. + */ + LuaRef* mReturnValue; +}; + +void LuaScriptingCallContext::setReturnValue(LuaRef* returnValue) +{ + delete returnValue; + mReturnValue = returnValue; +} + +LuaRef* LuaScriptingCallContext::getReturnValue() +{ + return mReturnValue; +} + +} + +#endif diff --git a/src/components/ogre/scripting/LuaScriptingProvider.cpp b/src/components/ogre/scripting/LuaScriptingProvider.cpp index e35f494..f902905 100644 --- a/src/components/ogre/scripting/LuaScriptingProvider.cpp +++ b/src/components/ogre/scripting/LuaScriptingProvider.cpp @@ -44,6 +44,7 @@ extern "C" { //#include #include #include "LuaHelper.h" +#include "LuaScriptingCallContext.h" TOLUA_API int tolua_Ogre_open (lua_State* tolua_S); TOLUA_API int tolua_Eris_open (lua_State* tolua_S); @@ -79,7 +80,9 @@ void LuaScriptingProvider::stop() try { ///we want to clear up the lua environment without destroying it (lua_close destroys it) std::string shutdownScript("for key,value in pairs(_G) do if key ~= \"_G\" and key ~= \"pairs\" then _G[key] = nil end end"); - executeScript(shutdownScript); + { + executeScript(shutdownScript, 0); + } forceGC(); } catch (...) { S_LOG_WARNING("Error when stopping lua."); @@ -167,19 +170,35 @@ lua_State* LuaScriptingProvider::getLuaState() void LuaScriptingProvider::loadScript(Ember::ResourceWrapper& resWrapper) { + executeScriptImpl(std::string(resWrapper.getDataPtr(), resWrapper.getSize()), 0, resWrapper.getName()); +} + +void LuaScriptingProvider::executeScript(const std::string& scriptCode, Ember::IScriptingCallContext* callContext) +{ + + executeScriptImpl(scriptCode, static_cast(callContext), ""); +} + +void LuaScriptingProvider::executeScriptImpl(const std::string& scriptCode, LuaScriptingCallContext* luaCallContext, const std::string& scriptName) +{ try { - - // load code into lua int top = lua_gettop(mLuaState); - int loaderr = luaL_loadbuffer(mLuaState, resWrapper.getDataPtr(), resWrapper.getSize(), resWrapper.getName().c_str()); - + int loaderr = luaL_loadbuffer(mLuaState, scriptCode.c_str(), scriptCode.length(), scriptCode.c_str()); + if (loaderr) { std::string errMsg(lua_tostring(mLuaState,-1)); lua_settop(mLuaState,top); - throw Ember::Exception("Unable to load Lua script file: '"+resWrapper.getName()+"'\n\n"+errMsg+"\n"); + if (!scriptName.empty()) + { + throw Ember::Exception("Unable to load Lua script file: '"+scriptName+"'\n\n"+errMsg+"\n"); + } + else + { + throw Ember::Exception("Unable to load Lua script: '" + scriptCode + "'\n\n"+errMsg+"\n"); + } } - + ///push our error handling method before calling the code int error_index = lua_gettop(mLuaState); #if LUA51 @@ -188,78 +207,56 @@ void LuaScriptingProvider::loadScript(Ember::ResourceWrapper& resWrapper) lua_pushliteral(mLuaState, "_TRACEBACK"); lua_rawget(mLuaState, LUA_GLOBALSINDEX); /* get traceback function */ #endif - lua_insert(mLuaState, error_index);/* put it under chunk and args */ - + lua_insert(mLuaState, error_index); - // call it - if (lua_pcall(mLuaState,0,0,error_index)) + /// load code into lua and call it + int error, nresults; + int level = lua_gettop(mLuaState); // top of stack position + // if we have context to store return values, then get them + if (luaCallContext) { - std::string errMsg(lua_tostring(mLuaState,-1)); - lua_settop(mLuaState,top); - throw Ember::Exception("Unable to execute Lua script file: '"+resWrapper.getName()+"'\n\n"+errMsg+"\n"); + error = lua_pcall(mLuaState, 0, LUA_MULTRET, error_index); + nresults = lua_gettop(mLuaState) - level; // number of results } - - lua_settop(mLuaState,top); // just in case :P - - -// getScriptModule().executeScriptFile(scriptName); - } catch (const CEGUI::Exception& ex) { - throw Ember::Exception(ex.getMessage().c_str()); - } catch( const CEGUI::String& str ) - { - throw Ember::Exception(str.c_str()); - } catch (const Ember::Exception& ex) { - throw ex; - } catch (...) { - throw Ember::Exception("Unknown error."); - } -/* } catch (const Ogre::Exception& ex) { - throw Ember::Exception("Error when loading script " + scriptName + ". Message: " + ex.get); - }*/ -} - -void LuaScriptingProvider::executeScript(const std::string& scriptCode) -