1111 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212 * See the License for the specific language governing permissions and
1313 * limitations under the License.
14- *
14+ *
1515 * Copyright (C) 2020-present, TBOOX Open Source Group.
1616 *
1717 * @author ruki
@@ -30,17 +30,26 @@ extern "C"{
3030 * private implemention
3131 */
3232
33+ static tb_byte_t const g_luafiles_data[] = {
34+ #include " luafiles.xmz.h"
35+ };
36+
37+ static tb_int_t lni_test_hello (lua_State* lua) {
38+ lua_pushliteral (lua, " hello xmake!" );
39+ return 1 ;
40+ }
41+
3342// pe.add_libraries("x.dll", {"a.dll", "b.dll"})
3443static tb_int_t lni_pe_add_libraries (lua_State* lua)
3544{
36- try
45+ try
3746 {
3847 // get arguments
3948 tb_char_t const * inputfile = luaL_checkstring (lua, 1 );
4049 tb_char_t const * outputfile = luaL_checkstring (lua, 2 );
4150 if (!inputfile || !outputfile || !lua_istable (lua, 3 )) throw " invalid arguments!" ;
4251
43- // add libraries
52+ // add libraries
4453 tb_size_t n = lua_objlen (lua, 3 );
4554 if (n > 0 )
4655 {
@@ -62,7 +71,7 @@ static tb_int_t lni_pe_add_libraries(lua_State* lua)
6271#endif
6372 }
6473 }
65- catch (std::exception const & e)
74+ catch (std::exception const & e)
6675 {
6776 lua_pushboolean (lua, tb_false);
6877 lua_pushstring (lua, e.what ());
@@ -75,14 +84,14 @@ static tb_int_t lni_pe_add_libraries(lua_State* lua)
7584// elf.add_libraries("libx.so", {"liba.so", "libb.so"})
7685static tb_int_t lni_elf_add_libraries (lua_State* lua)
7786{
78- try
87+ try
7988 {
8089 // get arguments
8190 tb_char_t const * inputfile = luaL_checkstring (lua, 1 );
8291 tb_char_t const * outputfile = luaL_checkstring (lua, 2 );
8392 if (!inputfile || !outputfile || !lua_istable (lua, 3 )) throw " invalid arguments!" ;
8493
85- // add libraries
94+ // add libraries
8695 tb_size_t n = lua_objlen (lua, 3 );
8796 if (n > 0 )
8897 {
@@ -98,7 +107,7 @@ static tb_int_t lni_elf_add_libraries(lua_State* lua)
98107 elf_binary->write (outputfile);
99108 }
100109 }
101- catch (std::exception const & e)
110+ catch (std::exception const & e)
102111 {
103112 lua_pushboolean (lua, tb_false);
104113 lua_pushstring (lua, e.what ());
@@ -111,7 +120,7 @@ static tb_int_t lni_elf_add_libraries(lua_State* lua)
111120// elf.detect_arch("libx.so")
112121static tb_int_t lni_elf_detect_arch (lua_State* lua)
113122{
114- try
123+ try
115124 {
116125 // get arguments
117126 tb_char_t const * inputfile = luaL_checkstring (lua, 1 );
@@ -138,7 +147,7 @@ static tb_int_t lni_elf_detect_arch(lua_State* lua)
138147 break ;
139148 }
140149 }
141- catch (std::exception const & e)
150+ catch (std::exception const & e)
142151 {
143152 lua_pushnil (lua);
144153 lua_pushstring (lua, e.what ());
@@ -150,14 +159,14 @@ static tb_int_t lni_elf_detect_arch(lua_State* lua)
150159// macho.add_libraries("libx.so", {"liba.dylib", "libb.dylib"})
151160static tb_int_t lni_macho_add_libraries (lua_State* lua)
152161{
153- try
162+ try
154163 {
155164 // get arguments
156165 tb_char_t const * inputfile = luaL_checkstring (lua, 1 );
157166 tb_char_t const * outputfile = luaL_checkstring (lua, 2 );
158167 if (!inputfile || !outputfile || !lua_istable (lua, 3 )) throw " invalid arguments!" ;
159168
160- // add libraries
169+ // add libraries
161170 tb_size_t n = lua_objlen (lua, 3 );
162171 if (n > 0 )
163172 {
@@ -176,7 +185,7 @@ static tb_int_t lni_macho_add_libraries(lua_State* lua)
176185 macho_binary->write (outputfile);
177186 }
178187 }
179- catch (std::exception const & e)
188+ catch (std::exception const & e)
180189 {
181190 lua_pushboolean (lua, tb_false);
182191 lua_pushstring (lua, e.what ());
@@ -190,15 +199,15 @@ static tb_int_t lni_macho_add_libraries(lua_State* lua)
190199static tb_void_t lni_initalizer (xm_engine_ref_t engine, lua_State* lua)
191200{
192201 // register pe module
193- static luaL_Reg const lni_pe_funcs[] =
202+ static luaL_Reg const lni_pe_funcs[] =
194203 {
195204 {" add_libraries" , lni_pe_add_libraries}
196205 , {tb_null, tb_null}
197206 };
198207 xm_engine_register (engine, " pe" , lni_pe_funcs);
199208
200209 // register elf module
201- static luaL_Reg const lni_elf_funcs[] =
210+ static luaL_Reg const lni_elf_funcs[] =
202211 {
203212 {" add_libraries" , lni_elf_add_libraries}
204213 , {" detect_arch" , lni_elf_detect_arch}
@@ -207,12 +216,13 @@ static tb_void_t lni_initalizer(xm_engine_ref_t engine, lua_State* lua)
207216 xm_engine_register (engine, " elf" , lni_elf_funcs);
208217
209218 // register macho module
210- static luaL_Reg const lni_macho_funcs[] =
219+ static luaL_Reg const lni_macho_funcs[] =
211220 {
212221 {" add_libraries" , lni_macho_add_libraries}
213222 , {tb_null, tb_null}
214223 };
215224 xm_engine_register (engine, " macho" , lni_macho_funcs);
225+ xm_engine_add_embedfiles (engine, g_luafiles_data, sizeof (g_luafiles_data));
216226}
217227
218228/* //////////////////////////////////////////////////////////////////////////////////////
0 commit comments