this is basically a design document version - it sets the scenery for upcoming additions
This commit is contained in:
parent
32aac45162
commit
550d27273f
1504 changed files with 1051518 additions and 127 deletions
1
src/scripting/CMakeLists.txt
Normal file
1
src/scripting/CMakeLists.txt
Normal file
|
@ -0,0 +1 @@
|
|||
add_subdirectory(src)
|
32
src/scripting/include/pw/scripting/script.hpp
Normal file
32
src/scripting/include/pw/scripting/script.hpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#ifndef PW_SCRIPTING_SCRIPT_HPP
|
||||
#define PW_SCRIPTING_SCRIPT_HPP
|
||||
|
||||
#include <pw/scripting/scripting.hpp>
|
||||
|
||||
namespace pw {
|
||||
|
||||
class script {
|
||||
protected:
|
||||
|
||||
scripting::state _state;
|
||||
scripting::table _namespace;
|
||||
|
||||
public:
|
||||
|
||||
script();
|
||||
~script();
|
||||
|
||||
bool load(const std::string &s);
|
||||
|
||||
int run(const std::string& s);
|
||||
|
||||
protected:
|
||||
|
||||
void load_modules();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
15
src/scripting/include/pw/scripting/scripting.hpp
Normal file
15
src/scripting/include/pw/scripting/scripting.hpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
#ifndef PW_SCRIPTING_SCRIPTING_HPP
|
||||
#define PW_SCRIPTING_SCRIPTING_HPP
|
||||
|
||||
#include "sol.hpp"
|
||||
#include <lua.hpp>
|
||||
|
||||
namespace pw {
|
||||
|
||||
// include external namespace of sol
|
||||
namespace scripting = sol;
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
23
src/scripting/src/CMakeLists.txt
Normal file
23
src/scripting/src/CMakeLists.txt
Normal file
|
@ -0,0 +1,23 @@
|
|||
|
||||
set(hdrs
|
||||
../include/pw/scripting/script.hpp
|
||||
../include/pw/scripting/scripting.hpp
|
||||
)
|
||||
|
||||
set(srcs
|
||||
script.cpp
|
||||
)
|
||||
|
||||
add_library(pwscripting
|
||||
STATIC
|
||||
${hdrs}
|
||||
${srcs}
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
pwscripting
|
||||
PUBLIC
|
||||
../include
|
||||
)
|
||||
|
||||
target_link_libraries(pwscripting lua pwcore)
|
56
src/scripting/src/script.cpp
Normal file
56
src/scripting/src/script.cpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
#include "pw/scripting/script.hpp"
|
||||
#include "pw/core/vector.hpp"
|
||||
|
||||
|
||||
pw::script::script() {
|
||||
|
||||
// create global pw namespace
|
||||
_namespace = _state.create_named_table("pw");
|
||||
|
||||
// add the script as a user type
|
||||
_namespace.new_usertype<script>("script",
|
||||
"initialize",&script::load_modules,
|
||||
"run",&script::run
|
||||
);
|
||||
|
||||
// add this instance as "script"
|
||||
_namespace.set("script",this);
|
||||
}
|
||||
|
||||
pw::script::~script()
|
||||
{
|
||||
_state.collect_garbage();
|
||||
}
|
||||
|
||||
bool pw::script::load(const std::string &s)
|
||||
{
|
||||
return _state.load(s.c_str());
|
||||
}
|
||||
|
||||
int pw::script::run(const std::string &s)
|
||||
{
|
||||
return _state.script(s.c_str()).get<int>();
|
||||
}
|
||||
|
||||
void pw::script::load_modules() {
|
||||
|
||||
// open all libraries
|
||||
_state.open_libraries();
|
||||
|
||||
typedef double Scalar;
|
||||
|
||||
_namespace.set("pi",Pi<Scalar>());
|
||||
|
||||
_namespace.new_usertype<vector3d>("vector3",
|
||||
"set",&vector3d::set,
|
||||
"x", scripting::property(scripting::resolve<const Scalar&() const>(&vector3d::x), &vector3d::set_x),
|
||||
"y", scripting::property(scripting::resolve<const Scalar&() const>(&vector3d::y), &vector3d::set_y),
|
||||
"z", scripting::property(scripting::resolve<const Scalar&() const>(&vector3d::z), &vector3d::set_z),
|
||||
"v",&vector3d::values
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue