// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]tundra/src/LuaInterface.cpp
// Function: t2::RunBuildScript(lua_State*, char const**, int)
bool RunBuildScript(lua_State *L, const char** args, int argc_count)
{
  // Push our error handler on the stack now (before the chunk to run)
  lua_pushcclosure(L, LuaGetTraceback, 0);
  int error_index = lua_gettop(L);

  switch (luaL_loadbuffer(L, s_BootSnippet, sizeof(s_BootSnippet)-1, "boot_snippet"))
  {
  case LUA_ERRMEM    : Croak("out of memory");
  case LUA_ERRSYNTAX : Croak("syntax error\n%s\n", lua_tostring(L, -1));
  }

  // Expose the path to tundra2 -- we're not that executable, so we'll need to find it.
  {
    PathBuffer exe_path;
    PathInit(&exe_path, GetExePath());
    PathStripLast(&exe_path);
    PathConcat(&exe_path, "tundra2" TUNDRA_EXE_SUFFIX);

    char tundra2_exe[kMaxPathLength];
    PathFormat(tundra2_exe, &exe_path);

    lua_pushstring(L, tundra2_exe);
    lua_setglobal(L, "TundraExePath");
  }

  // Push args from the command line
  for (int i = 0; i < argc_count; ++i)
  {
    lua_pushstring(L, args[i]);
  }

  int res = lua_pcall(L, /*narg:*/argc_count, /*nres:*/1, /*errorfunc:*/ error_index);

  if (0 == res)
  {
    return true;
  }
  else
  {
    // pcall failed
    if (lua_isstring(L, -1))
    {
      fprintf(stderr, "\nLua error\n%s\n", lua_tostring(L, -1));
    }
    return false;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4d0, %rsp            # imm = 0x4D0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x1bf(%rip), %rsi       # 0x7310
xorl %edx, %edx
callq 0x2a930
movq -0x10(%rbp), %rdi
callq 0x29910
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x461e1(%rip), %rsi     # 0x4d350
leaq 0x45f94(%rip), %rcx     # 0x4d10a
movl $0x2e, %edx
callq 0x2d590
movl %eax, %ecx
movl %ecx, -0x4bc(%rbp)
subl $0x3, %eax
je 0x71aa
jmp 0x718f
movl -0x4bc(%rbp), %eax
subl $0x4, %eax
jne 0x71cd
jmp 0x719c
leaq 0x45f74(%rip), %rdi     # 0x4d117
movb $0x0, %al
callq 0xba60
movq -0x10(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0x2a310
movq %rax, %rsi
leaq 0x45f5f(%rip), %rdi     # 0x4d125
movb $0x0, %al
callq 0xba60
callq 0xc100
movq %rax, %rsi
leaq -0x2ac(%rbp), %rdi
xorl %edx, %edx
callq 0xd180
leaq -0x2ac(%rbp), %rdi
callq 0xd680
leaq -0x2ac(%rbp), %rdi
leaq 0x45f39(%rip), %rsi     # 0x4d136
callq 0xd6e0
leaq -0x4b0(%rbp), %rdi
leaq -0x2ac(%rbp), %rsi
callq 0xd8d0
movq -0x10(%rbp), %rdi
leaq -0x4b0(%rbp), %rsi
callq 0x2a7a0
movq -0x10(%rbp), %rdi
movl $0xffffd8ee, %esi       # imm = 0xFFFFD8EE
leaq 0x45f09(%rip), %rdx     # 0x4d13e
callq 0x2b030
movl $0x0, -0x4b4(%rbp)
movl -0x4b4(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x7278
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movslq -0x4b4(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x2a7a0
movl -0x4b4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4b4(%rbp)
jmp 0x7244
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl -0x20(%rbp), %ecx
movl $0x1, %edx
callq 0x2b550
movl %eax, -0x4b8(%rbp)
xorl %eax, %eax
cmpl -0x4b8(%rbp), %eax
jne 0x72a2
movb $0x1, -0x1(%rbp)
jmp 0x72f4
movq -0x10(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x29fb0
cmpl $0x0, %eax
je 0x72f0
movq 0x5bd14(%rip), %rax     # 0x62fd0
movq (%rax), %rax
movq %rax, -0x4c8(%rbp)
movq -0x10(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %edx
callq 0x2a310
movq -0x4c8(%rbp), %rdi
movq %rax, %rdx
leaq 0x45e63(%rip), %rsi     # 0x4d14c
movb $0x0, %al
callq 0x6630
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x4d0, %rsp            # imm = 0x4D0
popq %rbp
retq
nopw %cs:(%rax,%rax)