Skip to content

Instantly share code, notes, and snippets.

@airekans
Last active December 16, 2015 19:09
Show Gist options
  • Save airekans/5482972 to your computer and use it in GitHub Desktop.
Save airekans/5482972 to your computer and use it in GitHub Desktop.
wxLua wrapper to make use wxLua easier.
#include "wxbind/include/wxbinddefs.h"
#include "wxbind/include/wxcore_bind.h"
WXLUA_DECLARE_BIND_ALL
wxLuaState& GetWxLuaState()
{
struct wxLuaStateInstance
{
wxLuaState m_wxLuaState;
wxLuaStateInstance()
{
// Initialize the wxLua bindings we want to use.
// See notes for WXLUA_DECLARE_BIND_ALL above.
WXLUA_IMPLEMENT_BIND_ALL
// When this function returns wxApp:MainLoop() will be called by wxWidgets
// and so we want the Lua code wx.wxGetApp:MailLoop() to not
// prematurely start it.
wxLuaState::sm_wxAppMainLoop_will_run = true;
m_wxLuaState = wxLuaState(wxTheApp, wxID_ANY);
}
};
static wxLuaStateInstance wxLStateInstance;
return wxLStateInstance.m_wxLuaState;
}
class wxLuaWindow
{
wxString m_wxLuaScript;
wxLuaState& m_wxLuaState;
public:
wxLuaWindow(wxWindow* parent, const wxString& wxLuaScript)
: m_wxLuaScript(wxLuaScript),
m_wxLuaState(GetWxLuaState())
{
// wxlua_pushargs(m_wxlState.GetLuaState(), argv, argc, 1);
// just run it, lua gives a nice error message on failure
m_wxLuaState.wxluaT_PushUserDataType(parent, wxluatype_wxWindow, false);
m_wxLuaState.lua_SetGlobal("parent_window");
m_wxLuaState.RunFile(m_wxLuaScript);
}
virtual ~wxLuaWindow()
{
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment