forked from Fluorohydride/ygopro-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscriptlib.cpp
71 lines (69 loc) · 1.68 KB
/
scriptlib.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* scriptlib.cpp
*
* Created on: 2010-7-29
* Author: Argon
*/
#include "scriptlib.h"
#include "duel.h"
int32 scriptlib::check_param(lua_State* L, int32 param_type, int32 index, int32 retfalse) {
int32 result;
switch (param_type) {
case PARAM_TYPE_CARD:
if (lua_isuserdata(L, index)) {
result = **(int32**)lua_touserdata(L, index);
if(result == 1)
return TRUE;
}
if(retfalse)
return FALSE;
luaL_error(L, "Parameter %d should be \"Card\".", index);
break;
case PARAM_TYPE_GROUP:
if (lua_isuserdata(L, index)) {
result = **(int32**)lua_touserdata(L, index);
if(result == 2)
return TRUE;
}
if(retfalse)
return FALSE;
luaL_error(L, "Parameter %d should be \"Group\".", index);
break;
case PARAM_TYPE_EFFECT:
if (lua_isuserdata(L, index)) {
result = **(int32**)lua_touserdata(L, index);
if(result == 3)
return TRUE;
}
if(retfalse)
return FALSE;
luaL_error(L, "Parameter %d should be \"Effect\".", index);
break;
case PARAM_TYPE_FUNCTION:
if (lua_isfunction(L, index))
return TRUE;
if(retfalse)
return FALSE;
luaL_error(L, "Parameter %d should be \"Function\".", index);
break;
case PARAM_TYPE_STRING:
if (lua_isstring(L, index))
return TRUE;
if(retfalse)
return FALSE;
luaL_error(L, "Parameter %d should be \"String\".", index);
break;
}
return FALSE;
}
int32 scriptlib::check_param_count(lua_State* L, int32 count) {
if (lua_gettop(L) < count)
luaL_error(L, "%d Parameters are needed.", count);
return TRUE;
}
int32 scriptlib::check_action_permission(lua_State* L) {
duel* pduel = interpreter::get_duel_info(L);
if(pduel->lua->no_action)
luaL_error(L, "Action is not allowed here.");
return TRUE;
}