View difference between Paste ID: NEBkazcG and L4ut7E2B
SHOW: | | - or go back to the newest paste.
1
#include "mmyy.hpp"
2
3
#include <stdio.h>
4
5
#pragma comment(lib, "lua51.lib")
6
#pragma comment(lib, "mmyy.lib")
7
8
class  MyState : public mmyy::State
9
{
10
public:
11
	// this has one fix for the Push function in mmyy::State, so if you don't put this here 
12
	// you will not be able to use Push from base if you declare your own Push overloads
13-
    void Msg(const char * str)
13+
	// see http://www.cplusplus.com/forum/general/15761/ for more info
14-
    {
14+
15-
        printf("%s", str);
15+
	MMYY_DECLARE_HELPERS
16-
    }
16+
17-
    void MsgN(const char * str)
17+
18-
    {
18+
	void Msg(const char * str)
19-
        printf("%s\n", str);
19+
20-
    }
20+
		printf("%s", str);
21-
    void OnError(const char * str)
21+
22-
    {
22+
	void MsgN(const char * str)
23-
        printf("[lua error] %s\n", str);
23+
24-
    }
24+
		printf("%s\n", str);
25
	}
26-
	// this will give us some nice functions to easily push and get MyState
26+
	void OnError(const char * str)
27
	{
28
		printf("[lua error] %s\n", str);
29-
	// a workaround to make it so we can call Push from base (implement this ???)
29+
30-
	template <typename T>
30+
31-
	void Push(T var)
31+
	// this will give us some nice functions to handle MyState
32
	// Push(MyState *var) 
33-
		mmyy::State::Push(var);
33+
	// ToState(int idx, MyState *def) 
34
	// ToState(int idx, check = true)
35
	// it will use "state" as its metaname
36
	MMYY_WRAP_CLASS(MyState, State, state)
37
};
38
39
// if we only have one state, we assume that this will always be the state used when a lua function is called
40
MyState *my;
41
42
LUALIB_FUNCTION(_G, State)
43
{
44
	auto self = new MyState();
45
46
	my->Push(self);
47
48
	return 1;
49
}
50
51
// uh oh
52
LUALIB_FUNCTION(_G, GetCurrentState)
53
{
54
	my->Push(my);
55
56
	return 1;
57
}
58
59
LUAMTA_FUNCTION(state, Error)
60
{
61
	auto self = my->ToState(1);
62
63
	self->Error(my->ToString(2));
64
65
	return 0;
66
}
67
68
LUAMTA_FUNCTION(state, RunString)
69
{
70
	auto self = my->ToState(1);
71
72
	my->Push(self->RunString(my->ToString(2)));
73
74
	return 1;
75
}
76
77
int main()
78-
    my = new MyState();
78+
79
	my = new MyState();
80-
    my->SetPlatformName("a");
80+
81
	my->RunString("state = State()");
82-
    my->RunString("state = State()");
82+
83
	my->RunString("state:Error('aaaaaaaaaaaaaaaa')");
84
	my->RunString("print(state.hello)");
85
86
	my->RunString("state = GetCurrentState()");
87
	my->RunString("state:RunString('aisjdiasjd iasjdi asjidj sad')");
88
89
	return 0;
90-
    return 0;
90+
91-
}
91+
92
/*
93
[lua error] aaaaaaaaaaaaaaaa
94
hello world
95
[lua error] [string "aisjdiasjd iasjdi asjidj sad"]:1: '=' expected near 'iasjdi'
96
*/