From 3502e9c7234daf1b12f6dc7f545d361d5cee105d Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Mon, 20 Feb 2012 16:26:48 -0600 Subject: [PATCH] Add set_package_preload(). Conflicts: src/CMakeLists.txt --- luabind/set_package_preload.hpp | 54 ++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 2 ++ src/set_package_preload.cpp | 55 +++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 luabind/set_package_preload.hpp create mode 100644 src/set_package_preload.cpp diff --git a/luabind/set_package_preload.hpp b/luabind/set_package_preload.hpp new file mode 100644 index 00000000..048f91b6 --- /dev/null +++ b/luabind/set_package_preload.hpp @@ -0,0 +1,54 @@ +/** @file + @brief Header + + @date 2012 + + @author + Ryan Pavlik + and + http://academic.cleardefinition.com/ + Iowa State University Virtual Reality Applications Center + Human-Computer Interaction Graduate Program +*/ + +// Copyright Iowa State University 2012. +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE +// OR OTHER DEALINGS IN THE SOFTWARE. + +#pragma once +#ifndef INCLUDED_set_package_preload_hpp_GUID_563c882e_86f7_4ea7_8603_4594ea41737e +#define INCLUDED_set_package_preload_hpp_GUID_563c882e_86f7_4ea7_8603_4594ea41737e + +// Internal Includes +#include +#include + +// Library/third-party includes +// - none + +// Standard includes +// - none + + +namespace luabind { + + LUABIND_API void set_package_preload(lua_State * L, const char * modulename, int (*loader) (lua_State *)); +} +#endif // INCLUDED_set_package_preload_hpp_GUID_563c882e_86f7_4ea7_8603_4594ea41737e diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6c6f7ebd..033a9adf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,6 +16,7 @@ set(luabind_SRCS open.cpp pcall.cpp scope.cpp + set_package_preload.cpp stack_content_by_name.cpp weak_ref.cpp wrapper_base.cpp) @@ -54,6 +55,7 @@ set(luabind_HDRS ../luabind/raw_policy.hpp ../luabind/return_reference_to_policy.hpp ../luabind/scope.hpp + ../luabind/set_package_preload.hpp ../luabind/shared_ptr_converter.hpp ../luabind/tag_function.hpp ../luabind/typeid.hpp diff --git a/src/set_package_preload.cpp b/src/set_package_preload.cpp new file mode 100644 index 00000000..a1af3702 --- /dev/null +++ b/src/set_package_preload.cpp @@ -0,0 +1,55 @@ +/** + @file + @brief Implementation + + @date 2012 + + @author + Ryan Pavlik + and + http://academic.cleardefinition.com/ + Iowa State University Virtual Reality Applications Center + Human-Computer Interaction Graduate Program +*/ + +// Copyright Iowa State University 2012. +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: + +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE +// OR OTHER DEALINGS IN THE SOFTWARE. + +// Internal Includes +#include +#include + +// Library/third-party includes +// - none + +// Standard includes +// - none + + +namespace luabind { + LUABIND_API void set_package_preload(lua_State * L, const char * modulename, int (*loader) (lua_State *)) { + rawget(rawget(globals(L), "package"), "preload").push(L); + lua_pushcclosure(L, loader, 0); + lua_setfield(L, -2, modulename); + lua_pop(L, 1); + } + +} // namespace luabind