bit of playing around on Linux
This commit is contained in:
parent
ac18a84a9c
commit
6461a56e17
11 changed files with 96 additions and 102 deletions
|
@ -1,23 +1,18 @@
|
|||
|
||||
|
||||
include_directories(
|
||||
${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/glad/include
|
||||
|
||||
|
||||
)
|
||||
|
||||
add_library(pw
|
||||
STATIC
|
||||
binding.hpp
|
||||
binding.cpp
|
||||
context.hpp
|
||||
context.cpp
|
||||
script.hpp
|
||||
script.cpp
|
||||
core.hpp
|
||||
core.cpp
|
||||
window.hpp
|
||||
window.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(pw lualib glfw)
|
||||
target_link_libraries(pw lualib glfw glad)
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
#ifndef PW_BINDING_HPP
|
||||
#define PW_BINDING_HPP
|
||||
|
||||
#include <lua.hpp>
|
||||
|
||||
namespace pw {
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -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);
|
||||
}
|
|
@ -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
|
|
@ -2,6 +2,6 @@
|
|||
#define PW_CORE_HPP
|
||||
|
||||
|
||||
#include "context.hpp"
|
||||
#include "script.hpp"
|
||||
|
||||
#endif
|
||||
|
|
35
src/core/script.cpp
Normal file
35
src/core/script.cpp
Normal 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
29
src/core/script.hpp
Normal 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
|
|
@ -1,9 +1,15 @@
|
|||
#include "window.hpp"
|
||||
|
||||
#include "glad/glad.h"
|
||||
|
||||
|
||||
pw::window::window() {
|
||||
|
||||
_window = glfwCreateWindow(640, 480, "pixwerxs", NULL, NULL);
|
||||
|
||||
glfwMakeContextCurrent(_window);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
|
||||
}
|
||||
|
||||
pw::window::~window() {
|
||||
|
@ -14,7 +20,6 @@ pw::window::~window() {
|
|||
bool pw::window::update()
|
||||
{
|
||||
if (!glfwWindowShouldClose(_window)) {
|
||||
glfwMakeContextCurrent(_window);
|
||||
|
||||
// do other stuff
|
||||
|
||||
|
|
|
@ -8,6 +8,15 @@
|
|||
|
||||
namespace pw {
|
||||
|
||||
class window;
|
||||
|
||||
class context {
|
||||
GLFWwindow* _window;
|
||||
public:
|
||||
context(window& other);
|
||||
~context();
|
||||
};
|
||||
|
||||
|
||||
class window {
|
||||
|
||||
|
@ -22,10 +31,12 @@ public:
|
|||
bool update();
|
||||
|
||||
void set_title(const char* t);
|
||||
void set_size(int w, int h);
|
||||
|
||||
context* get_context();
|
||||
|
||||
static void load(sol::table &ns);
|
||||
void set_size(int w, int h);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,15 +1,20 @@
|
|||
|
||||
#include "core.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue