-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathteste.c
38 lines (30 loc) · 1.12 KB
/
teste.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
#include "src/one.c"
LuaCEmbedNamespace lua_n;
LuaCEmbedResponse *add_cfunc(LuaCEmbed *args){
double first_num = lua_n.args.get_double(args,0);
double second_num = lua_n.args.get_double(args,1);
if(lua_n.has_errors(args)){
char *message = lua_n.get_error_message(args);
return lua_n.response.send_error(message);
}
double result = first_num + second_num;
return lua_n.response.send_double(result);
}
LuaCEmbedResponse *sub_cfunc(LuaCEmbed *args){
double first_num = lua_n.args.get_double(args,0);
double second_num = lua_n.args.get_double(args,1);
if(lua_n.has_errors(args)){
char *message = lua_n.get_error_message(args);
return lua_n.response.send_error(message);
}
double result = first_num - second_num;
return lua_n.response.send_double(result);
}
int luaopen_my_lib(lua_State *state){
lua_n = newLuaCEmbedNamespace();
//functions will be only assescible by the required reciver
LuaCEmbed * l = lua_n.newLuaLib(state);
lua_n.add_callback(l,"add",add_cfunc);
lua_n.add_callback(l,"sub",sub_cfunc);
return lua_n.perform(l);
}