Skip to content

Commit 301cbc3

Browse files
att
1 parent 2fe66ad commit 301cbc3

File tree

7 files changed

+59
-50
lines changed

7 files changed

+59
-50
lines changed

LuaCEmbed.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31174,7 +31174,7 @@ void LuaCEmbedTable_set_long_prop(LuaCEmbedTable *self , const char *name,lua_I
3117431174

3117531175
lua_getglobal(self->main_object->state,self->global_name);
3117631176
lua_pushstring(self->main_object->state,name);
31177-
lua_pushnumber(self->main_object->state,(double)value);
31177+
lua_pushinteger(self->main_object->state,value);
3117831178
lua_settable(self->main_object->state,-3);
3117931179
lua_settop(self->main_object->state, 0);
3118031180

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ DESPITE BEING 100% COVERED BY TESTS, THIS LIBRARY IS NOT CONSIDERED PRODUCTION R
1717
[Link to Web Site](oui.tec.br)
1818

1919
#### Download Link
20-
[Click Here to Download](https://github.com/OUIsolutions/LuaCEmbed/releases/download/v0.779/LuaCEmbed.h)
20+
[Click Here to Download](https://github.com/OUIsolutions/LuaCEmbed/releases/download/v0.75/LuaCEmbed.h)
2121

2222

2323
### Instalation
@@ -1486,20 +1486,20 @@ type string
14861486
value: indexable random string
14871487
------------------------------------------
14881488
index: 1
1489+
key: single
1490+
type boolean
1491+
value: 1
1492+
------------------------------------------
1493+
index: 2
14891494
key: name
14901495
type string
14911496
value: Mateus
14921497
------------------------------------------
1493-
index: 2
1498+
index: 3
14941499
key: age
14951500
type number
14961501
value: 27.000000
14971502
------------------------------------------
1498-
index: 3
1499-
key: single
1500-
type boolean
1501-
value: 1
1502-
------------------------------------------
15031503
15041504
~~~
15051505

output_test

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
==28265== Memcheck, a memory error detector
2-
==28265== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
3-
==28265== Using Valgrind-3.23.0 and LibVEX; rerun with -h for copyright info
4-
==28265== Command: ./tests/main_test/table_handle/T_setting_sub_table/exec.out
5-
==28265== Parent PID: 26976
6-
==28265==
7-
==28265==
8-
==28265== HEAP SUMMARY:
9-
==28265== in use at exit: 0 bytes in 0 blocks
10-
==28265== total heap usage: 143 allocs, 143 frees, 12,957 bytes allocated
11-
==28265==
12-
==28265== All heap blocks were freed -- no leaks are possible
13-
==28265==
14-
==28265== For lists of detected and suppressed errors, rerun with: -s
15-
==28265== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
1+
==19889== Memcheck, a memory error detector
2+
==19889== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
3+
==19889== Using Valgrind-3.23.0 and LibVEX; rerun with -h for copyright info
4+
==19889== Command: ./tests/main_test/table_handle/T_setting_sub_table/exec.out
5+
==19889== Parent PID: 18375
6+
==19889==
7+
==19889==
8+
==19889== HEAP SUMMARY:
9+
==19889== in use at exit: 0 bytes in 0 blocks
10+
==19889== total heap usage: 143 allocs, 143 frees, 12,957 bytes allocated
11+
==19889==
12+
==19889== All heap blocks were freed -- no leaks are possible
13+
==19889==
14+
==19889== For lists of detected and suppressed errors, rerun with: -s
15+
==19889== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

src/LuaCEmbed/table/table/setters/keys/fdefine.keys.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void LuaCEmbedTable_set_long_prop(LuaCEmbedTable *self , const char *name,lua_I
8888

8989
lua_getglobal(self->main_object->state,self->global_name);
9090
lua_pushstring(self->main_object->state,name);
91-
lua_pushnumber(self->main_object->state,(double)value);
91+
lua_pushinteger(self->main_object->state,value);
9292
lua_settable(self->main_object->state,-3);
9393
lua_settop(self->main_object->state, 0);
9494

teste.c

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,38 @@
11

2-
3-
4-
#include "lib.c"
52
#include "src/one.c"
6-
LuaCEmbedNamespace lua_n1;
73

8-
int main(){
4+
LuaCEmbedNamespace lua_n;
95

10-
lua_n1 = newLuaCEmbedNamespace();
11-
LuaCEmbed * main_obj = lua_n1.newLuaEvaluation();
126

7+
LuaCEmbedResponse *add_cfunc(LuaCEmbed *args){
8+
double first_num = lua_n.args.get_double(args,0);
9+
double second_num = lua_n.args.get_double(args,1);
1310

14-
lua_n1.load_lib_from_c(main_obj,luaopen_my_lib,"calc");
15-
if(lua_n1.has_errors(main_obj)){
16-
printf("erro de carrgamento = '%s'\n",lua_n1.get_error_message(main_obj));
17-
lua_n1.free(main_obj);
18-
return 0;
11+
if(lua_n.has_errors(args)){
12+
char *message = lua_n.get_error_message(args);
13+
return lua_n.response.send_error(message);
1914
}
15+
double result = first_num + second_num;
16+
return lua_n.response.send_double(result);
17+
}
18+
LuaCEmbedResponse *sub_cfunc(LuaCEmbed *args){
19+
double first_num = lua_n.args.get_double(args,0);
20+
double second_num = lua_n.args.get_double(args,1);
2021

21-
lua_n1.evaluate(main_obj,"x = calc.add(0,20)");
22-
if(lua_n1.has_errors(main_obj)){
23-
printf("erro interno = '%s'\n",lua_n1.get_error_message(main_obj));
24-
return 0;
22+
if(lua_n.has_errors(args)){
23+
char *message = lua_n.get_error_message(args);
24+
return lua_n.response.send_error(message);
2525
}
26-
printf("%lld\n",lua_n1.globals.get_long(main_obj,"x"));
27-
lua_n1.free(main_obj);
28-
return 0;
26+
double result = first_num - second_num;
27+
return lua_n.response.send_double(result);
28+
}
29+
int luaopen_my_lib(lua_State *state){
30+
lua_n = newLuaCEmbedNamespace();
31+
//functions will be only assescible by the required reciver
32+
LuaCEmbed * l = lua_n.newLuaLib(state);
33+
lua_n.add_callback(l,"add",add_cfunc);
34+
lua_n.add_callback(l,"sub",sub_cfunc);
35+
36+
return lua_n.perform(l);
37+
2938
}

tests/LuaCEmbed.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31174,7 +31174,7 @@ void LuaCEmbedTable_set_long_prop(LuaCEmbedTable *self , const char *name,lua_I
3117431174

3117531175
lua_getglobal(self->main_object->state,self->global_name);
3117631176
lua_pushstring(self->main_object->state,name);
31177-
lua_pushnumber(self->main_object->state,(double)value);
31177+
lua_pushinteger(self->main_object->state,value);
3117831178
lua_settable(self->main_object->state,-3);
3117931179
lua_settop(self->main_object->state, 0);
3118031180

tests/main_test/table_handle/S_iterating_over_table/expected.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ type string
44
value: indexable random string
55
------------------------------------------
66
index: 1
7+
key: single
8+
type boolean
9+
value: 1
10+
------------------------------------------
11+
index: 2
712
key: name
813
type string
914
value: Mateus
1015
------------------------------------------
11-
index: 2
16+
index: 3
1217
key: age
1318
type number
1419
value: 27.000000
1520
------------------------------------------
16-
index: 3
17-
key: single
18-
type boolean
19-
value: 1
20-
------------------------------------------

0 commit comments

Comments
 (0)