I can't commit right now, for a couple reasons (I don't have the time to clean up my codebase, test this, and bugfix four more bugs), so here is the source code for the requested mission functions. Source code goes in lua.cpp.
Under "lua_lib l_Mission("Mission", "mn", "Mission library");"
LUA_FUNC(getMissionName, l_Mission, NULL, "string", "Gets mission name")
{
if(!(Game_mode & GM_IN_MISSION))
return LUA_RETURN_NIL;
return lua_set_args(L, "s", Game_current_mission_filename);
}
And under the "LUA_FUNC(getShipByIndex" function
LUA_FUNC(getNumWeapons, l_Mission, NULL, "Number of weapon objects in mission",
"Gets number of weapon objects in mission. Note that this is only accurate for one frame.")
{
return lua_set_args(L, "i", Num_weapons);
}
LUA_FUNC(getWeaponByIndex, l_Mission, "Index", "Weapon handle, or false if invalid index",
"Gets weapon by its order in the mission. "
"Note that as weapons are added, they may take the index of destroyed ships. "
"An index is only good for one frame.")
{
int idx;
if(!lua_get_args(L, "i", &idx))
return LUA_RETURN_NIL;
//Remember, Lua indices start at 0.
int count=1;
for(int i = 0; i < MAX_WEAPONS; i++)
{
if (Weapons[i].weapon_info_index < 0 || Weapons[i].objnum < 0 || Objects[Weapons[i].objnum].type != OBJ_WEAPON)
continue;
if(count == idx) {
return lua_set_args(L, "o", l_Weapon.Set(object_h(&Objects[Weapons[i].objnum])));
}
count++;
}
return LUA_RETURN_FALSE;
}
I have test-compiled these but not tested them.