Skip to content

Commit 4d379ed

Browse files
att
1 parent 72e0b87 commit 4d379ed

File tree

8 files changed

+55
-28
lines changed

8 files changed

+55
-28
lines changed

README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ DESPITE BEING 100% COVERED BY TESTS, THIS LIBRARY IS NOT CONSIDERED PRODUCTION R
2222

2323
### Instalation
2424
Like all Oui librarys, the LuaCEmbed addopt the ideia of single file lib, so you just need to copy the **LuaCEmbed.h** file
25-
into your project, and compile with gcc/clang
25+
into your project, and compile with gcc/clang
2626

2727
~~~c
2828
#include "LuaCEmbed.h"
2929
LuaCEmbedNamespace lua_n;
3030

3131
int main(int argc, char *argv[]){
32-
32+
3333
lua_n = newLuaCEmbedNamespace();
3434
LuaCEmbed * l = lua_n.newLuaEvaluation();
3535
lua_n.evaluate(l,"r = 30");
3636
long calc = lua_n.get_evaluation_long(l,"r + 20");
3737
printf("result %ld",calc);
38-
38+
3939
if(lua_n.has_errors(l)){
4040
printf("error: %s\n",lua_n.get_error_message(l));
4141
}
@@ -55,9 +55,9 @@ result 50
5555

5656
### Runting Native functions
5757
<h3 style="color:red;">
58-
NEVER CALL THE FUNCTION 'load_native_libs' IF YOU DON TRUST IN THE USER
58+
NEVER CALL THE FUNCTION 'load_native_libs' IF YOU DON TRUST IN THE USER
5959
</h3>
60-
You can load native lua functions by the usage of **load_native_libs** function
60+
You can load native lua functions by the usage of **load_native_libs** function
6161

6262

6363
~~~c
@@ -121,26 +121,27 @@ LuaCEmbedResponse *sub_cfunc(LuaCEmbed *args){
121121
double result = first_num - second_num;
122122
return lua_n.response.send_double(result);
123123
}
124+
124125
int luaopen_my_lib(lua_State *state){
125126
lua_n = newLuaCEmbedNamespace();
126-
//functions will be only assescible by the required reciver
127127
LuaCEmbed * l = lua_n.newLuaLib(state);
128128
lua_n.add_callback(l,"add",add_cfunc);
129129
lua_n.add_callback(l,"sub",sub_cfunc);
130130

131-
return lua_n.perform(l);
132-
131+
return lua_n.send_self_as_lib(l);
133132
}
133+
134+
134135
~~~
135136
Compile the code with:
136137
~~~shell
137-
gcc -Wall -shared -fpic -o my_lib.so main.c
138+
gcc -Wall -shared -fpic -o my_lib.so main.c
138139
~~~
139140

140141

141142
than you can call into your lua code
142143

143-
~~~lua
144+
~~~lua
144145

145146
local lib = require("my_lib")
146147

@@ -152,7 +153,7 @@ print("y",y)
152153
~~~
153154
### Lib Props
154155
you can determine library props into your lib:
155-
~~~c
156+
~~~c
156157

157158

158159
#include "LuaCEmbed.h"
@@ -181,7 +182,7 @@ int luaopen_my_lib(lua_State *state){
181182
182183
testing with lua:
183184
184-
~~~lua
185+
~~~lua
185186
186187
lib = require("my_lib")
187188
print("long_prop",lib.long_prop)
@@ -1010,7 +1011,7 @@ int main(int argc, char *argv[]){
10101011
printf("error: %s\n",lua_n.get_error_message(l));
10111012
}
10121013
printf("resullt :%ld\n",result);
1013-
1014+
10141015
lua_n.free(l);
10151016

10161017
return 0;
@@ -1051,7 +1052,7 @@ int main(int argc, char *argv[]){
10511052
printf("error: %s\n",lua_n.get_error_message(l));
10521053
}
10531054
printf("resullt :%lf\n",result);
1054-
1055+
10551056
lua_n.free(l);
10561057

10571058
return 0;
@@ -1092,7 +1093,7 @@ int main(int argc, char *argv[]){
10921093
printf("error: %s\n",lua_n.get_error_message(l));
10931094
}
10941095
printf("resullt :%s\n",result);
1095-
1096+
10961097
lua_n.free(l);
10971098

10981099
return 0;
@@ -1133,7 +1134,7 @@ int main(int argc, char *argv[]){
11331134
printf("error: %s\n",lua_n.get_error_message(l));
11341135
}
11351136
printf("resullt :%d\n",result);
1136-
1137+
11371138
lua_n.free(l);
11381139

11391140
return 0;
@@ -1178,7 +1179,7 @@ int main(int argc, char *argv[]){
11781179
}
11791180

11801181
printf("value of created.a = %s\n",a);
1181-
1182+
11821183
lua_n.free(l);
11831184

11841185
return 0;
@@ -1380,7 +1381,7 @@ LuaCEmbedResponse * show_table(LuaCEmbed *args){
13801381

13811382
printf("------------------------------------------\n");
13821383
}
1383-
1384+
13841385
return NULL;
13851386

13861387
}
@@ -2262,4 +2263,3 @@ It will produce
22622263
result of r.a internal text
22632264
22642265
~~~
2265-

lib.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ LuaCEmbedResponse *sub_cfunc(LuaCEmbed *args){
2828
}
2929
int luaopen_my_lib(lua_State *state){
3030
lua_n = newLuaCEmbedNamespace();
31-
32-
33-
//functions will be only assescible by the required reciver
3431
LuaCEmbed * l = lua_n.newLuaLib(state);
35-
// lua_n.dangerous_raise_error_jumping(l,"tesddddt");
3632

3733
lua_n.add_callback(l,"add",add_cfunc);
3834
lua_n.add_callback(l,"sub",sub_cfunc);
39-
40-
return lua_n.perform(l);
35+
lua_n.evaluate(l,"r = 320");
36+
if(lua_n.has_errors(l)){
37+
lua_n.dangerous_raise_self_error_jumping(l);
38+
return 0;
39+
}
40+
return lua_n.send_self_as_lib(l);
4141
}

src/LuaCEmbed/errors/fdeclare.errors.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ void privateLuaCEmbed_raise_error_not_jumping(LuaCEmbed *self, const char *error
1616

1717
void LuaCEmbed_dangerous_raise_error_jumping(LuaCEmbed *self,const char *error_msg,...);
1818

19-
void LuaCEmbed_dangerous_raise_self_error_jumping(LuaCEmbed *self,const char *error_msg,...);
19+
void LuaCEmbed_dangerous_raise_self_error_jumping(LuaCEmbed *self);

src/LuaCEmbed/errors/fdefine.errors.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void LuaCEmbed_dangerous_raise_error_jumping(LuaCEmbed *self,const char *error_m
6666
lua_error(self->state);
6767
}
6868

69-
void LuaCEmbed_dangerous_raise_self_error_jumping(LuaCEmbed *self,const char *error_msg,...){
69+
void LuaCEmbed_dangerous_raise_self_error_jumping(LuaCEmbed *self){
7070
if(!LuaCEmbed_has_errors(self)){
7171
return;
7272
}

src/LuaCEmbed/lib_start/fdeclare.lib_start.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ int private_LuaCemb_internal_free(lua_State *L);
99
LuaCEmbed * newLuaCEmbedLib(lua_State *state);
1010

1111
int LuaCembed_perform(LuaCEmbed *self);
12+
13+
int LuaCembed_send_self_as_lib(LuaCEmbed *self);
14+
15+
int LuaCembed_send_global_as_lib(LuaCEmbed *self,const char *global_name);

src/LuaCEmbed/lib_start/fdefine.lib_start.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,20 @@ int LuaCembed_perform(LuaCEmbed *self){
6969
free(lib_main_table);
7070
return 1;
7171
}
72+
73+
int LuaCembed_send_self_as_lib(LuaCEmbed *self){
74+
return LuaCembed_perform(self);
75+
}
76+
77+
int LuaCembed_send_global_as_lib(LuaCEmbed *self,const char *global_name){
78+
if(global_name == NULL){
79+
return 0;
80+
}
81+
82+
lua_getglobal(self->state,global_name);
83+
int type = lua_type(self->state,-1);
84+
if(type == LUA_CEMBED_NIL){
85+
return 0;
86+
}
87+
return 1;
88+
}

src/namespace/LuaCEmbedNamespace/fdefine.LuaCEmbedNamespace.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ LuaCEmbedNamespace newLuaCEmbedNamespace(){
1313
self.newLuaEvaluation = newLuaCEmbedEvaluation;
1414
self.set_delete_function = LuaCembed_set_delete_function;
1515
self.perform = LuaCembed_perform;
16+
self.send_self_as_lib = LuaCembed_send_self_as_lib;
17+
self.send_global_as_lib = LuaCembed_send_global_as_lib;
18+
1619
self.load_native_libs = LuaCEmbed_load_native_libs;
1720
self.set_memory_limit = LuaCEmbed_set_memory_limit;
1821
self.clear_errors = LuaCEmbed_clear_errors;

src/namespace/LuaCEmbedNamespace/typesD.LuaCEmbedNamespace.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ typedef struct{
1717
void (*load_native_libs)(LuaCEmbed *self);
1818
void (*load_lib_from_c)(LuaCEmbed *self,int (*callback)(lua_State *l),const char *name);
1919
int (*perform)(LuaCEmbed *self);
20+
int (*send_self_as_lib)(LuaCEmbed *self);
21+
int (*send_global_as_lib)(LuaCEmbed *self,const char *global_name);
22+
2023
const char * (*convert_arg_code)(int arg_code);
2124
void (*set_memory_limit)(LuaCEmbed *self, double limit);
2225

@@ -49,7 +52,7 @@ typedef struct{
4952
void (*add_global_callback)(LuaCEmbed *self, const char *callback_name, LuaCEmbedResponse* (*callback)(LuaCEmbed *args) );
5053

5154
void (*dangerous_raise_error_jumping)(LuaCEmbed *self,const char *error_msg,...);
52-
void (*dangerous_raise_self_error_jumping)(LuaCEmbed *self,const char *error_msg,...);
55+
void (*dangerous_raise_self_error_jumping)(LuaCEmbed *self);
5356

5457
void (*free)(LuaCEmbed *self);
5558

0 commit comments

Comments
 (0)