bit of playing around on Linux

This commit is contained in:
Hartmut Seichter 2017-06-29 14:00:03 +02:00
parent ac18a84a9c
commit 6461a56e17
11 changed files with 96 additions and 102 deletions

View file

@ -1,23 +1,18 @@
include_directories( include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../deps/glfw-3.2.1/include ${CMAKE_CURRENT_SOURCE_DIR}/../deps/glfw-3.2.1/include
${CMAKE_CURRENT_SOURCE_DIR}/../deps/lua-5.3.4/src ${CMAKE_CURRENT_SOURCE_DIR}/../deps/lua-5.3.4/src
${CMAKE_CURRENT_SOURCE_DIR}/../deps/glad/include ${CMAKE_CURRENT_SOURCE_DIR}/../deps/glad/include
) )
add_library(pw add_library(pw
STATIC STATIC
binding.hpp script.hpp
binding.cpp script.cpp
context.hpp
context.cpp
core.hpp core.hpp
core.cpp core.cpp
window.hpp window.hpp
window.cpp window.cpp
) )
target_link_libraries(pw lualib glfw) target_link_libraries(pw lualib glfw glad)

View file

View file

@ -1,11 +0,0 @@
#ifndef PW_BINDING_HPP
#define PW_BINDING_HPP
#include <lua.hpp>
namespace pw {
}
#endif

View file

@ -1,39 +0,0 @@
#include "context.hpp"
#include "window.hpp"
pw::context::context()
: _running(true)
{
_lua.open_libraries();
sol::table pw = _lua.create_named_table("pw");
window::load(pw);
// luaL_openlibs(_state);
}
pw::context::~context()
{
// lua_close(_state);
}
bool pw::context::update()
{
return _running;
}
void pw::context::yield()
{
}
void pw::context::script(const char *s)
{
_lua.script("w = pw.window.new()");
_lua.script("w:set_title(\"pixwerks alpha\")");
_lua.script("w:set_size(320,240)");
_lua.script("while w:update() do end");
// luaL_loadstring(_state,s);
// int r = lua_pcall(_state,0,LUA_MULTRET,0);
}

View file

@ -1,36 +0,0 @@
#ifndef PW_CONTEXT_HPP
#define PW_CONTEXT_HPP
#include <lua.hpp>
#include <memory>
#include <sol.hpp>
namespace pw {
class context {
sol::state _lua;
bool _running;
public:
context();
~context();
bool update();
void yield();
void set_running(bool s) { _running = s; }
bool is_running() const { return _running; }
void script(const char* s);
};
}
#endif

View file

@ -2,6 +2,6 @@
#define PW_CORE_HPP #define PW_CORE_HPP
#include "context.hpp" #include "script.hpp"
#endif #endif

35
src/core/script.cpp Normal file
View file

@ -0,0 +1,35 @@
#include "script.hpp"
#include "window.hpp"
pw::script::script()
{
// open all libraries
_lua.open_libraries();
// load pw namespace
sol::table pw = _lua.create_named_table("pw");
window::load(pw);
}
pw::script::~script()
{
}
void pw::script::run(const char *s)
{
sol::function_result res = _lua.script(s);
// res.status() == sol::f
// _lua.script("w = pw.window.new()");
// _lua.script("w:set_title(\"pixwerks alpha\")");
// _lua.script("w:set_size(320,240)");
// _lua.script("while w:update() do end");
// luaL_loadstring(_state,s);
// int r = lua_pcall(_state,0,LUA_MULTRET,0);
}

29
src/core/script.hpp Normal file
View file

@ -0,0 +1,29 @@
#ifndef PW_SCRIPT_HPP
#define PW_SCRIPT_HPP
#include <lua.hpp>
#include <memory>
#include <sol.hpp>
namespace pw {
class script {
sol::state _lua;
public:
script();
~script();
bool update();
void run(const char* s);
};
}
#endif

View file

@ -1,9 +1,15 @@
#include "window.hpp" #include "window.hpp"
#include "glad/glad.h"
pw::window::window() { pw::window::window() {
_window = glfwCreateWindow(640, 480, "pixwerxs", NULL, NULL); _window = glfwCreateWindow(640, 480, "pixwerxs", NULL, NULL);
glfwMakeContextCurrent(_window);
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
} }
pw::window::~window() { pw::window::~window() {
@ -14,7 +20,6 @@ pw::window::~window() {
bool pw::window::update() bool pw::window::update()
{ {
if (!glfwWindowShouldClose(_window)) { if (!glfwWindowShouldClose(_window)) {
glfwMakeContextCurrent(_window);
// do other stuff // do other stuff

View file

@ -8,6 +8,15 @@
namespace pw { namespace pw {
class window;
class context {
GLFWwindow* _window;
public:
context(window& other);
~context();
};
class window { class window {
@ -22,10 +31,12 @@ public:
bool update(); bool update();
void set_title(const char* t); void set_title(const char* t);
void set_size(int w, int h);
context* get_context();
static void load(sol::table &ns); static void load(sol::table &ns);
void set_size(int w, int h);
}; };
} }

View file

@ -1,15 +1,20 @@
#include "core.hpp" #include "core.hpp"
#include <string>
int main(int argc,char* argv[]) { int main(int argc,char* argv[]) {
pw::context ctx; pw::script s;
// while (ctx.update()) {
// ctx.yield();
// }
ctx.script(0L); std::string thescript = "w = pw.window.new()"
"w:set_title(\"pixwerks alpha\")"
"w:set_size(320,240)"
"while w:update() do end" ;
s.run(thescript.c_str());
return 0L; return 0L;
} }