美文网首页
64位lua引擎如何支持32位luac编译出来的二进制字节码?

64位lua引擎如何支持32位luac编译出来的二进制字节码?

作者: 自由快挂 | 来源:发表于2017-06-22 09:49 被阅读597次

    原文 http://www.jianshu.com/p/3c49cf454502

    不知道原作者是基于哪一个版本的 Lua 源码修改的,原理和 debug 参考原文吧。
    现在奉上 Lua-5.3.4 的修改方案:

    diff --git a/src/ldump.c b/src/ldump.c
    index 016e300..08fc883 100644
    --- a/src/ldump.c
    +++ b/src/ldump.c
    @@ -74,7 +74,7 @@ static void DumpString (const TString *s, DumpState *D) {
       if (s == NULL)
         DumpByte(0, D);
       else {
    -    size_t size = tsslen(s) + 1;  /* include trailing '\0' */
    +    int size = tsslen(s) + 1;  /* include trailing '\0' */
         const char *str = getstr(s);
         if (size < 0xFF)
           DumpByte(cast_int(size), D);
    @@ -187,7 +187,7 @@ static void DumpHeader (DumpState *D) {
       DumpByte(LUAC_FORMAT, D);
       DumpLiteral(LUAC_DATA, D);
       DumpByte(sizeof(int), D);
    -  DumpByte(sizeof(size_t), D);
    +  DumpByte(sizeof(int), D);
       DumpByte(sizeof(Instruction), D);
       DumpByte(sizeof(lua_Integer), D);
       DumpByte(sizeof(lua_Number), D);
    diff --git a/src/loslib.c b/src/loslib.c
    index 5a94eb9..b73a3cd 100644
    --- a/src/loslib.c
    +++ b/src/loslib.c
    @@ -139,14 +139,15 @@ static time_t l_checktime (lua_State *L, int arg) {
     
     
     static int os_execute (lua_State *L) {
    -  const char *cmd = luaL_optstring(L, 1, NULL);
    -  int stat = system(cmd);
    -  if (cmd != NULL)
    -    return luaL_execresult(L, stat);
    -  else {
    -    lua_pushboolean(L, stat);  /* true if there is a shell */
    -    return 1;
    -  }
    +    return 0;
    +//  const char *cmd = luaL_optstring(L, 1, NULL);
    +//  int stat = system(cmd);
    +//  if (cmd != NULL)
    +//    return luaL_execresult(L, stat);
    +//  else {
    +//    lua_pushboolean(L, stat);  /* true if there is a shell */
    +//    return 1;
    +//  }
     }
     
     
    diff --git a/src/luaconf.h b/src/luaconf.h
    index f37bea0..c8e4f65 100644
    --- a/src/luaconf.h
    +++ b/src/luaconf.h
    @@ -33,8 +33,7 @@
     ** ensure that all software connected to Lua will be compiled with the
     ** same configuration.
     */
    -/* #define LUA_32BITS */
    -
    +#define LUA_32BITS
     
     /*
     @@ LUA_USE_C89 controls the use of non-ISO-C89 features.
    diff --git a/src/lundump.c b/src/lundump.c
    index 4080af9..2e22117 100644
    --- a/src/lundump.c
    +++ b/src/lundump.c
    @@ -86,7 +86,7 @@ static lua_Integer LoadInteger (LoadState *S) {
     
     
     static TString *LoadString (LoadState *S) {
    -  size_t size = LoadByte(S);
    +  int size = LoadByte(S);
       if (size == 0xFF)
         LoadVar(S, size);
       if (size == 0)
    @@ -241,7 +241,7 @@ static void checkHeader (LoadState *S) {
         error(S, "format mismatch in");
       checkliteral(S, LUAC_DATA, "corrupted");
       checksize(S, int);
    -  checksize(S, size_t);
    +  checksize(S, int);
       checksize(S, Instruction);
       checksize(S, lua_Integer);
       checksize(S, lua_Number);
    

    https://github.com/c0i/lua32

    所以 Luajit 也有可能这样改喽?不过以前修改过 Luajit 的 op,碰灰,前景不容乐观。

    相关文章

      网友评论

          本文标题:64位lua引擎如何支持32位luac编译出来的二进制字节码?

          本文链接:https://www.haomeiwen.com/subject/mhixcxtx.html