Skip to content

Commit 3502e9c

Browse files
rpavlikOberon00
authored andcommitted
Add set_package_preload().
Conflicts: src/CMakeLists.txt
1 parent 61e8e8f commit 3502e9c

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed

luabind/set_package_preload.hpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/** @file
2+
@brief Header
3+
4+
@date 2012
5+
6+
@author
7+
Ryan Pavlik
8+
9+
http://academic.cleardefinition.com/
10+
Iowa State University Virtual Reality Applications Center
11+
Human-Computer Interaction Graduate Program
12+
*/
13+
14+
// Copyright Iowa State University 2012.
15+
// Permission is hereby granted, free of charge, to any person obtaining a
16+
// copy of this software and associated documentation files (the "Software"),
17+
// to deal in the Software without restriction, including without limitation
18+
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
19+
// and/or sell copies of the Software, and to permit persons to whom the
20+
// Software is furnished to do so, subject to the following conditions:
21+
22+
// The above copyright notice and this permission notice shall be included
23+
// in all copies or substantial portions of the Software.
24+
25+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
26+
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
27+
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
28+
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
29+
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
30+
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31+
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
33+
// OR OTHER DEALINGS IN THE SOFTWARE.
34+
35+
#pragma once
36+
#ifndef INCLUDED_set_package_preload_hpp_GUID_563c882e_86f7_4ea7_8603_4594ea41737e
37+
#define INCLUDED_set_package_preload_hpp_GUID_563c882e_86f7_4ea7_8603_4594ea41737e
38+
39+
// Internal Includes
40+
#include <luabind/config.hpp>
41+
#include <luabind/lua_state_fwd.hpp>
42+
43+
// Library/third-party includes
44+
// - none
45+
46+
// Standard includes
47+
// - none
48+
49+
50+
namespace luabind {
51+
52+
LUABIND_API void set_package_preload(lua_State * L, const char * modulename, int (*loader) (lua_State *));
53+
}
54+
#endif // INCLUDED_set_package_preload_hpp_GUID_563c882e_86f7_4ea7_8603_4594ea41737e

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ set(luabind_SRCS
1616
open.cpp
1717
pcall.cpp
1818
scope.cpp
19+
set_package_preload.cpp
1920
stack_content_by_name.cpp
2021
weak_ref.cpp
2122
wrapper_base.cpp)
@@ -54,6 +55,7 @@ set(luabind_HDRS
5455
../luabind/raw_policy.hpp
5556
../luabind/return_reference_to_policy.hpp
5657
../luabind/scope.hpp
58+
../luabind/set_package_preload.hpp
5759
../luabind/shared_ptr_converter.hpp
5860
../luabind/tag_function.hpp
5961
../luabind/typeid.hpp

src/set_package_preload.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
@file
3+
@brief Implementation
4+
5+
@date 2012
6+
7+
@author
8+
Ryan Pavlik
9+
10+
http://academic.cleardefinition.com/
11+
Iowa State University Virtual Reality Applications Center
12+
Human-Computer Interaction Graduate Program
13+
*/
14+
15+
// Copyright Iowa State University 2012.
16+
// Permission is hereby granted, free of charge, to any person obtaining a
17+
// copy of this software and associated documentation files (the "Software"),
18+
// to deal in the Software without restriction, including without limitation
19+
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
20+
// and/or sell copies of the Software, and to permit persons to whom the
21+
// Software is furnished to do so, subject to the following conditions:
22+
23+
// The above copyright notice and this permission notice shall be included
24+
// in all copies or substantial portions of the Software.
25+
26+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
27+
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
28+
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
29+
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
30+
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
31+
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
32+
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
33+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
34+
// OR OTHER DEALINGS IN THE SOFTWARE.
35+
36+
// Internal Includes
37+
#include <luabind/set_package_preload.hpp>
38+
#include <luabind/object.hpp>
39+
40+
// Library/third-party includes
41+
// - none
42+
43+
// Standard includes
44+
// - none
45+
46+
47+
namespace luabind {
48+
LUABIND_API void set_package_preload(lua_State * L, const char * modulename, int (*loader) (lua_State *)) {
49+
rawget(rawget(globals(L), "package"), "preload").push(L);
50+
lua_pushcclosure(L, loader, 0);
51+
lua_setfield(L, -2, modulename);
52+
lua_pop(L, 1);
53+
}
54+
55+
} // namespace luabind

0 commit comments

Comments
 (0)