Modifying LJ to add a few math functions

  • From: Emil Dotchevski <emildotchevski@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 25 Jul 2013 17:32:21 -0700

Hello,

I'm trying to replace Lua with LJ on a XBOX 360 project, but
unfortunately the original Lua distribution was modified and I need to
replicate the changes to LJ.

What should I change in order to add functions to the math lib? I
added the functions to lib_math.c like so:

LJLIB_ASM(math_nmod)    LJLIB_REC(math_nmod)
{
  int x = lj_lib_checkint(L, 1);
  if (L->base+1 < L->top) {
    int y = lj_lib_checkint(L, 2);
        setintV(L->base-1, x%y);
        return FFH_RES(1);
  }
  return FFH_RETRY;
}

LJLIB_ASM(math_ndiv)    LJLIB_REC(math_nmod)
{
  int x = lj_lib_checkint(L, 1);
  if (L->base+1 < L->top) {
    int y = lj_lib_checkint(L, 2);
        setintV(L->base-1, x/y);
        return FFH_RES(1);
  }
  return FFH_RETRY;
}

LJLIB_ASM(math_pi)              LJLIB_REC(math_pi)
{
  setnumV(L->top++,3.14159265358979323846);
  return 1;
}

But apparently this is not sufficient, as I get the following build error:

Error: undefined fast function lj_ff_math_nmod

I looked around a bit until I realized that it's likely that I'll
break something if I try to resolve this on my own. I appreciate any
help.

Thanks,
Emil

Other related posts: