@@ -15,10 +15,19 @@ LuaCEmbed * newLuaCEmbedEvaluation(){
1515 return self ;
1616}
1717void LuaCEmbed_load_lib_from_c (LuaCEmbed * self ,int (* callback )(lua_State * l ),const char * name ){
18- int result = callback (self -> state );
19- if (result > 0 ){
20- lua_setglobal (self -> state ,name );
18+ if (LuaCEmbed_has_errors (self )){
19+ return ;
20+ }
21+
22+ lua_pushcfunction (self -> state , callback );
23+ int result = lua_pcall (self -> state ,0 ,1 ,0 );
24+ if (result ){
25+ privateLuaCEmbed_raise_error_not_jumping (self ,lua_tostring (self -> state ,-1 ));
26+ lua_settop (self -> state ,0 );
27+ return ;
2128 }
29+ lua_setglobal (self -> state ,name );
30+ lua_settop (self -> state ,0 );
2231}
2332void LuaCEmbed_load_native_libs (LuaCEmbed * self ) {
2433 luaL_openlibs (self -> state );
@@ -38,55 +47,14 @@ void LuaCEmbed_set_timeout(int seconds){
3847 lua_cembed_timeout = seconds ;
3948}
4049
41- char * LuaCEmbed_get_error_message (LuaCEmbed * self ){
42- if (!self ){
43- return NULL ;
44- }
4550
46- return self -> error_msg ;
47- }
48- void LuaCEmbed_clear_errors (LuaCEmbed * self ){
49- if (!self ){
50- return ;
51- }
52-
53- if (self -> error_msg ){
54- free (self -> error_msg );
55- self -> error_msg = NULL ;
56- }
57- }
5851void * privateLuaCEmbed_get_current_table_array (LuaCEmbed * self ){
5952 if (self -> current_function ){
6053 return self -> func_tables ;
6154 }
6255 return self -> global_tables ;
6356}
64- void privateLuaCEmbed_raise_error_not_jumping (LuaCEmbed * self , const char * error_msg , ...){
6557
66- if (LuaCEmbed_has_errors (self )){
67- return ;
68- }
69-
70- va_list args ;
71- va_start (args ,error_msg );
72- self -> error_msg = private_LuaCembed_format_vaarg (error_msg , args );
73- va_end (args );
74-
75- }
76-
77-
78-
79- bool LuaCEmbed_has_errors (LuaCEmbed * self ){
80- if (!self ){
81- return true;
82- }
83-
84- if (self -> error_msg ){
85- return true;
86- }
87-
88- return false;
89- }
9058
9159
9260
0 commit comments