Created
November 7, 2016 19:57
-
-
Save bobvodka/d02691888ad8ebedb5f10062c5d46eac to your computer and use it in GitHub Desktop.
Lua windowing bindings!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Part of the Windowing lib | |
WINDOWING_API void Initialise(sol::state &lua) | |
{ | |
msgRouter = std::make_unique<WindowMessageRouter>(WinMap); | |
// Register stuff with Lua or something... bleh | |
sol::table bonsai = lua["Bonsai"]; // get Bonsai table | |
auto windowing = bonsai.create_named("Windowing"); | |
windowing.set_function("DispatchMessages", &DispatchMessages); | |
windowing.set_function("CreateWindow", &CreateWin); | |
windowing.set_function("DestroyWindow", &DestroyWin); | |
typedef Bonsai::Windowing::Window BonsaiWindow; | |
windowing.new_usertype<BonsaiWindow>("Window", | |
"Visible", &BonsaiWindow::Visible, | |
"IsVisible", &BonsaiWindow::IsVisible, | |
// "SwitchModes", &BonsaiWindow::SwitchModes, // Needs WindowProperties defined | |
"SetSize", &BonsaiWindow::ChangeSize, | |
//"GetSize", &BonsaiWindow::GetSize, // need logic to return multiple values | |
"UpdatePosition", &BonsaiWindow::UpdatePosition, | |
//"GetPosition", &BonsaiWindow::GetPosition, // need logic to return multiple values | |
"SetTitle", &BonsaiWindow::SetTitle | |
); | |
windowing["Properties"] = windowing.create_with( | |
"FullScreen", winprops::fullscreen, | |
"Windowed", winprops::windowed | |
); | |
} | |
// And a framework test app | |
int APIENTRY wWinMain(_In_ HINSTANCE hInstance, | |
_In_opt_ HINSTANCE hPrevInstance, | |
_In_ LPWSTR lpCmdLine, | |
_In_ int nCmdShow) | |
{ | |
sol::state luaState; | |
luaState.open_libraries(sol::lib::base, sol::lib::package); | |
luaState.create_named_table("Bonsai"); // table for all the Bonsai stuff | |
Bonsai::Windowing::Initialise(luaState); | |
luaState.script("\ | |
win = Bonsai.Windowing.CreateWindow(\"Test Window\", 800, 600, Bonsai.Windowing.Properties.Windowed) \ | |
win:Visible(true) \ | |
\ | |
function Update()\ | |
v = Bonsai.Windowing.DispatchMessages() \ | |
return v \ | |
end \ | |
"); | |
std::function<bool ()> updateFunc = luaState["Update"]; | |
while (updateFunc()) | |
{ | |
Sleep(0); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment