added the standard LUA libraries to the LUA context

This commit is contained in:
Anselme 2017-08-28 16:51:26 +02:00
parent 9bccabfbba
commit f7616648be
4 changed files with 47 additions and 0 deletions

View File

@ -7,12 +7,17 @@
#include "SparrowInput/Version.h" #include "SparrowInput/Version.h"
#include "SparrowRenderer/Version.h" #include "SparrowRenderer/Version.h"
#include "SparrowSerializer/Version.h" #include "SparrowSerializer/Version.h"
#include "tools/utils.h"
#define LUA_DEFINE(var) S[#var]=var #define LUA_DEFINE(var) S[#var]=var
#define LUA_SET_FUN(var) m_script.set_function(#var,&ScriptNode::var,this);this->functions_name.push_back(#var); #define LUA_SET_FUN(var) m_script.set_function(#var,&ScriptNode::var,this);this->functions_name.push_back(#var);
ScriptNode::ScriptNode() ScriptNode::ScriptNode()
{ {
m_script.open_libraries(sol::lib::base);
m_script.open_libraries(sol::lib::math);
utils::initScriptingUtilsFunctions(this);
LUA_SET_FUN(getDeltaTime); LUA_SET_FUN(getDeltaTime);
LUA_SET_FUN(print); LUA_SET_FUN(print);
LUA_SET_FUN(version); LUA_SET_FUN(version);

View File

@ -21,6 +21,8 @@ public:
void version(); void version();
void clear(); void clear();
float getDeltaTime(); float getDeltaTime();
sol::state& getScriptEngine() { return m_script; }
void addAutoCompletionSymbol(const std::string& symbolName) { functions_name.push_back(symbolName); }
}; };

View File

@ -3,6 +3,7 @@
//#include "scene/scenetree.h" //#include "scene/scenetree.h"
#include "scene/meshnode.h" #include "scene/meshnode.h"
#include "iostream" #include "iostream"
#include "sparrowshell/scriptnode.h"
std::vector<std::string> utils::split(const std::string &line, char sep){ std::vector<std::string> utils::split(const std::string &line, char sep){
std::vector<std::string> tokens; std::vector<std::string> tokens;
@ -14,6 +15,41 @@ std::vector<std::string> utils::split(const std::string &line, char sep){
tokens.push_back(line.substr(start)); tokens.push_back(line.substr(start));
return tokens; return tokens;
} }
void utils::initScriptingUtilsFunctions(ScriptNode* scriptNode)
{
}
void utils::initStandardScene()
{
/*
* GUI
*
* ENTITIES
* PLAYER
* MOBS
*
* OBJECTS
* ITEMS // the player can interact with it, it is permanent and is saved in the map
* GIBS // only for decorative purposes and ephemere
* PROJECTILES // ballistic object
*
* MAP
* ENVIRONMENT
* FOG
* SUN
* SKY
* GEOMETRY
* CHUNK_NODES // procedural geometry
* MODEL_NODES // modelized geometry
*
*
*
*
*/
}
/* /*
void utils::setPosition2D(MeshNode *mnode, glm::vec2 pos){ void utils::setPosition2D(MeshNode *mnode, glm::vec2 pos){
const glm::mat4 &tr = mnode->getTransform(); const glm::mat4 &tr = mnode->getTransform();
@ -42,3 +78,4 @@ void setDepth2D(MeshNode* mnode, float depth){
//mesh.setDepth(depth); //mesh.setDepth(depth);
} }
*/ */

View File

@ -6,10 +6,13 @@
#include <glm/glm.hpp> #include <glm/glm.hpp>
class MeshNode; class MeshNode;
class ScriptNode;
namespace utils namespace utils
{ {
std::vector<std::string> split(const std::string &line, char sep); std::vector<std::string> split(const std::string &line, char sep);
void initScriptingUtilsFunctions(ScriptNode* scriptNode);
void initStandardScene();
//void setPosition2D(MeshNode*, glm::vec2); //void setPosition2D(MeshNode*, glm::vec2);
//void resize2D(MeshNode*, glm::vec2, glm::vec2); //void resize2D(MeshNode*, glm::vec2, glm::vec2);
//void scale2D(MeshNode*, glm::vec2); //void scale2D(MeshNode*, glm::vec2);