7

I choose Lua 5.1 as my application's embedded scripting language, but when I port the application to a legacy platform runs LynxOS on PowerPC, thing seems going wrong.

I get following code run up on PC and every thing looks good:

void test_lua()
{
  const char *code = "foo = 5\n";
  double vfoo=0;
  lua_State *L = luaL_newstate();

  (void)luaL_loadbuffer(L, code, strlen(code), "line");
  (void)lua_pcall (L, 0, 0, 0);

  lua_getglobal(L, "foo");
  vfoo = lua_tonumber(L, -1);

  lua_close(L);

  myTrace("vfoo = %f", vfoo);
  for(;;);
}

with PC (Visual C++ 6.0) I got expecting "vfoo = 5.000000"

But with LynxOS/PowerPC I got "vfoo = 0.000000".

So what's going on for Lua on LynxOS/PowerPC ? I am wondering if there are some configurations for big-endian machine, I looked for it in "luaconf.h" but find nothing. I also tried the configuration item "LUA_USE_POSIX" but no help.

I know it's not a typical platform for lua programming. However, any suggestions are welcome and be appreciated.

Haiyuan Li
  • 377
  • 2
  • 10
  • 6
    The code seems right. I suggest you check the return values of `luaL_loadbuffer` and `lua_pcall` and print `luaL_typename(L,-1)` after `lua_getglobal`. – lhf Apr 01 '13 at 12:21
  • There are Lua test suites at . Try running them. If something is broken, some of the tests should fail, maybe giving you more info on what is broken. (The test code is dense and uncommented, but the assert line info should be enough to reconstruct what happened.) – nobody Sep 21 '13 at 23:56

1 Answers1

2

Endian-ness shouldn't affect the operation of the lua code. I have ported to several platforms that are not Win32, and I've run into times where the LUA_IEEE754TRICK that is used to convert a 64-bit double into an integer does not always work, but is enabled by default. Try undefining the LUA_IEEE754TRICK macro in luaconf.h.

I have also encountered clibs where the floating point printf/scanf functions were broken or unreliable, and I had to write my own custom version of lua_number2str.

I feel for you though. The lua engine is a large, black box that is confusing to step through and debug when something goes wrong with its internals. In my case it has usually been the compiler/clib's fault, but that doesn't make it any easier to make the 2 get along with each other.

Nathan Wiebe
  • 794
  • 5
  • 12
  • Thanks for the response. Actually it's hard to debug on our PPC/LynxOS platform as no efficient tool available,that's why I post this message here. The later story is the platform is eliminated and any effort about it get no encourage any more. – Haiyuan Li Dec 26 '13 at 06:59