Skip to content

Instantly share code, notes, and snippets.

@bobvodka
Created November 7, 2016 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobvodka/d02691888ad8ebedb5f10062c5d46eac to your computer and use it in GitHub Desktop.
Save bobvodka/d02691888ad8ebedb5f10062c5d46eac to your computer and use it in GitHub Desktop.
Lua windowing bindings!
// 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