diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index e4828de..2f4c7e6 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -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) diff --git a/src/core/binding.cpp b/src/core/binding.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/core/binding.hpp b/src/core/binding.hpp deleted file mode 100644 index cc1e7ba..0000000 --- a/src/core/binding.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PW_BINDING_HPP -#define PW_BINDING_HPP - -#include - -namespace pw { - - -} - -#endif diff --git a/src/core/context.cpp b/src/core/context.cpp index ff2bb63..e69de29 100644 --- a/src/core/context.cpp +++ b/src/core/context.cpp @@ -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); -} diff --git a/src/core/context.hpp b/src/core/context.hpp index 775c856..e69de29 100644 --- a/src/core/context.hpp +++ b/src/core/context.hpp @@ -1,36 +0,0 @@ -#ifndef PW_CONTEXT_HPP -#define PW_CONTEXT_HPP - -#include -#include -#include - -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 diff --git a/src/core/core.hpp b/src/core/core.hpp index 1ac796e..06d2702 100644 --- a/src/core/core.hpp +++ b/src/core/core.hpp @@ -2,6 +2,6 @@ #define PW_CORE_HPP -#include "context.hpp" +#include "script.hpp" #endif diff --git a/src/core/script.cpp b/src/core/script.cpp new file mode 100644 index 0000000..f8f5dfd --- /dev/null +++ b/src/core/script.cpp @@ -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); +} diff --git a/src/core/script.hpp b/src/core/script.hpp new file mode 100644 index 0000000..a369a5c --- /dev/null +++ b/src/core/script.hpp @@ -0,0 +1,29 @@ +#ifndef PW_SCRIPT_HPP +#define PW_SCRIPT_HPP + +#include +#include +#include + +namespace pw { + +class script { + + sol::state _lua; + +public: + + script(); + ~script(); + + bool update(); + + void run(const char* s); + +}; + +} + + + +#endif diff --git a/src/core/window.cpp b/src/core/window.cpp index 6d0afbb..1451d3e 100644 --- a/src/core/window.cpp +++ b/src/core/window.cpp @@ -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 diff --git a/src/core/window.hpp b/src/core/window.hpp index 5e9e475..89dcc07 100644 --- a/src/core/window.hpp +++ b/src/core/window.hpp @@ -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); + }; } diff --git a/src/engine/pixwerx.cpp b/src/engine/pixwerx.cpp index d60a803..916fd32 100644 --- a/src/engine/pixwerx.cpp +++ b/src/engine/pixwerx.cpp @@ -1,15 +1,20 @@ #include "core.hpp" +#include + 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; }