Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mmyy.hpp"
- #include <stdio.h>
- #pragma comment(lib, "lua51.lib")
- #pragma comment(lib, "mmyy.lib")
- class MyState : public mmyy::State
- {
- public:
- // redirect output if nesseceary
- void Msg(const char * str)
- {
- printf("%s", str);
- }
- void MsgN(const char * str)
- {
- printf("%s\n", str);
- }
- void OnError(const char * str)
- {
- printf("[lua error] %s\n", str);
- }
- // this will give us some nice functions to easily push and get MyState
- MMYY_WRAP_CLASS(MyState, State, state)
- // a workaround to make it so we can call Push from base (implement this ???)
- template <typename T>
- void Push(T var)
- {
- mmyy::State::Push(var);
- }
- };
- // if we only have one state, we assume that this will always be the state used when a lua function is called
- MyState *my;
- LUALIB_FUNCTION(_G, State)
- {
- auto self = new MyState();
- my->Push(self);
- return 1;
- }
- // uh oh
- LUALIB_FUNCTION(_G, GetCurrentState)
- {
- my->Push(my);
- return 1;
- }
- LUAMTA_FUNCTION(state, Error)
- {
- auto self = my->ToState(1);
- self->Error(my->ToString(2));
- return 0;
- }
- LUAMTA_FUNCTION(state, RunString)
- {
- auto self = my->ToState(1);
- my->Push(self->RunString(my->ToString(2)));
- return 1;
- }
- int main()
- {
- my = new MyState();
- my->SetPlatformName("a");
- my->RunString("state = State()");
- my->RunString("state.hello = 'hello world'");
- my->RunString("state:Error('aaaaaaaaaaaaaaaa')");
- my->RunString("print(state.hello)");
- my->RunString("state = GetCurrentState()");
- my->RunString("state:RunString('aisjdiasjd iasjdi asjidj sad')");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment