-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLuaUtils.c
105 lines (88 loc) · 2.29 KB
/
LuaUtils.c
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
#include "LuaUtils.h"
lua_State* state;
static const luaL_Reg libs_test[] = {
};
void Create_Lua()
{
state = luaL_newstate();
luaL_openlibs(state);
// LoadUserdata(state);
custom_OpenLibs(state);
Register_C_Functions();
//LoadUserdata(state);
//lua_atpanic(state,Lua_PanicFunc);
}
void Register_C_Functions()
{
lua_register(state, "Test_func", Example_Lua_FUNCTION);
lua_register(state, "GLBegin", GLBeginWrapper);
lua_register(state, "GLVertex3", GLVertexWrapper);
lua_register(state, "GLColor3", GLColorWrapper);
lua_register(state, "GLEnd", GLEndWrapper);
lua_register(state,"InitTestUserdata",initUserData);
}
int Example_Lua_FUNCTION(lua_State* L)
{
//if (lua_rawget(L, 1) == LUA_TFUNCTION) {
printf("%i",__LINE__);
// lua_call(L, 1, 0);
//}
//else {
//printf("lua_rawget(L, -1):%i",lua_rawget(L, 1));
//}
return 0;
}
lua_State* Get_Lua_State()
{
return state;
}
void CreateInterpertor(){
Create_Lua();
Register_C_Functions();
//initUserData(Get_Lua_State());
#ifdef HAS_READLINE_H
while(LUAIntLoop == true){
char* in = readline("lua>");
if(strcmp("exit",in) == 0){
LUAIntLoop = false;
}else if(strcmp("open_userdata",in) == 0){
LoadUserdata(state);
}
else{
//luaL_dostring(Get_Lua_State(),"print(_VERSION)");
if(luaL_dostring(Get_Lua_State(),in) != 0){
printf("%s\n",lua_tostring(Get_Lua_State(),-1));
}
}
}
#endif
}
int Lua_PanicFunc(lua_State* L){
}
void CreateInterpertor_file(){
Create_Lua();
Register_C_Functions();
//initUserData(Get_Lua_State());
while(LUAIntLoop == true){
char* in = readline("lua_file>");
// printf("The Lua Developement Interpertor\n");
if(strcmp("exit",in) == 0){
LUAIntLoop = false;
}else{
// luaL_dostring(Get_Lua_State(),"")
//if(access(in,F_OK) != 0 && access(in,R_OK) != 0){
// printf("The Specified file can't be opened! Error Message:%s",strerror(errno));
//}else{
if(luaL_dofile(Get_Lua_State(),in) != 0){
printf("%s\n",lua_tostring(Get_Lua_State(),-1));
}
//}
}
}
}
void custom_OpenLibs(lua_State* L){
luaL_getsubtable(L,LUA_REGISTRYINDEX,LUA_PRELOAD_TABLE);
lua_pushcfunction(L,initUserData);
lua_setfield(L,-2,"test");
lua_pop(L,1);
}