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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
extern "C" {
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
}
#include "common.h"
//Expose things to the lua state
void loadLLibs(lua_State* L){
lua_pushcfunction(L,luaopen_base);
lua_pushliteral(L,"");
lua_call(L,1,0);
lua_pushcfunction(L,luaopen_table);
lua_pushliteral(L,LUA_TABLIBNAME);
lua_call(L,1,0);
lua_pushcfunction(L,luaopen_string);
lua_pushliteral(L,LUA_STRLIBNAME);
lua_call(L,1,0);
lua_pushcfunction(L,luaopen_math);
lua_pushliteral(L,LUA_MATHLIBNAME);
lua_call(L,1,0);
lua_pushcfunction(L,luaopen_string);
lua_pushliteral(L,LUA_STRLIBNAME);
lua_call(L,1,0);
/*
lua_pushcfunction(L,luaopen_string);
lua_pushliteral(L,LUA_STRLIBNAME);
lua_call(L,1,0);
*/
}
int pushvector3i(lua_State* L,long a,long b,long c){
lua_newtable(L);
lua_pushinteger(L,1);
lua_pushinteger(L,a);
lua_settable(L,-3);
lua_pushinteger(L,2);
lua_pushinteger(L,b);
lua_settable(L,-3);
lua_pushinteger(L,3);
lua_pushinteger(L,c);
lua_settable(L,-3);
return 1;
}
int pushvector3d(lua_State* L,double a,double b,double c){
lua_newtable(L);//{}
lua_pushinteger(L,1);//{},1
lua_pushnumber(L,a);//{},1,a
lua_settable(L,-3);//{}
lua_pushinteger(L,2);//{},2
lua_pushnumber(L,b);//{},2,b
lua_settable(L,-3);//{}
lua_pushinteger(L,3);//{},3
lua_pushnumber(L,c);//{},3,c
lua_settable(L,-3);//{}
return 1;
}
int popvector3i(lua_State* L,long* a,long* b,long* c){//{v3}
lua_pushinteger(L,1);//{v3},1
lua_gettable(L,-2);//{v3},v3[1]
*a = lua_tointeger(L,-1);//{v3},v3[1]
lua_pop(L,1);//{v3}
lua_pushinteger(L,2);//{v3},2
lua_gettable(L,-2);//{v3},v3[2]
*b = lua_tointeger(L,-1);//{v3},v3[2]
lua_pop(L,1);//{v3}
lua_pushinteger(L,3);//{v3},3
lua_gettable(L,-2);//{v3},v3[3]
*c = lua_tointeger(L,-1);//{v3},v3[3]
lua_pop(L,1);//{v3}
lua_pop(L,1);//
return 0;
}
int popvector3d(lua_State* L,double* a,double* b,double* c){
lua_pushinteger(L,1);
lua_gettable(L,-2);
*a = lua_tonumber(L,-1);
lua_pop(L,1);
lua_pushinteger(L,2);
lua_gettable(L,-2);
*b = lua_tonumber(L,-1);
lua_pop(L,1);
lua_pushinteger(L,3);
lua_gettable(L,-2);
*c = lua_tonumber(L,-1);
lua_pop(L,1);
lua_pop(L,1);
return 0;
}
|