Its way out of date and a very basic implementation of Lua, there is no error or argument checking in the lib, this is frustrating when debugging and causes stupid runtime crashes with script errors like GameGuru, proper error checking should be added to the functions
for example, in my Lua projects I include the following functions
// Helper Functions
int AGKLUA_CountArgs(lua_State *L, int required)
{
// get the number of arguments on the stack
int received = lua_gettop(L);
// Do we have enough arguments
if (received == required)
{
return true;
}
else
{
// We do not have enough arguments
char buffer[50];
int result = sprintf(buffer, "%d arguments expected, %d arguments received.", required, received);
luaL_error(L, buffer);
return false;
}
}
const char * AGKLUA_CheckString(lua_State *L, int arg_index)
{
const char * result;
if (lua_isstring(L, arg_index))
{
result = lua_tostring(L, arg_index);
return result;
}
else
{
luaL_typeerror(L, arg_index, "String");
result = "";
return result;
}
}
int AGKLUA_CheckNumber(lua_State *L, int arg_index)
{
if (lua_isnumber(L, arg_index))
{
int result = (int)lua_tonumber(L, arg_index);
return result;
}
else
{
luaL_typeerror(L, arg_index, "Number");
}
return 0;
}
float AGKLUA_CheckFloat(lua_State *L, int arg_index)
{
if (lua_isnumber(L, arg_index))
{
float result = (float)lua_tonumber(L, arg_index);
return result;
}
else
{
luaL_typeerror(L, arg_index, "Number");
}
return 0.0f;
}
boolean AGKLUA_CheckBoolean(lua_State *L, int arg_index)
{
if (lua_isboolean(L, arg_index))
{
boolean result = (boolean)lua_toboolean(L, arg_index);
return result;
}
else
{
luaL_typeerror(L, arg_index, "Boolean");
}
return false;
}
int AGKLUA_CheckFunction(lua_State *L, int arg_index)
{
if (lua_isfunction(L, arg_index))
{
float result = lua_tocfunction(L, arg_index);
return result;
}
else
{
luaL_typeerror(L, arg_index, "Boolean");
return 0;
}
}
and usage:
int AGKLua_WorldToScreenX(lua_State *L)
{
// Get variables from lua
AGKLUA_CountArgs(L, 1);
float x = AGKLUA_CheckFloat(L, 1);
// Call function and push result
float result = agk::WorldToScreenX(x);
lua_pushnumber(L, result);
return 1;
}
int AGKLua_WorldToScreenY(lua_State *L)
{
// Get variables from lua
AGKLUA_CountArgs(L, 1);
float y = AGKLUA_CheckFloat(L, 1);
// Call function and push result
float result = agk::WorldToScreenY(y);
lua_pushnumber(L, result);
return 1;
}
int AGKLua_FixCameraToObject(lua_State *L)
{
// Get variables from lua
AGKLUA_CountArgs(L, 2);
int cameraID = AGKLUA_CheckNumber(L, 1);
int objID = AGKLUA_CheckNumber(L, 2);
// Call function and push result
agk::FixCameraToObject(cameraID, objID);
return 0;
}
int AGKLua_Debug(lua_State *L)
{
// Get variables from lua
AGKLUA_CountArgs(L, 1);
const char * value = AGKLUA_CheckString(L, 1);
// Send debug info to the editor
app::sendEditorString(g_Msg_Debug, value);
return 0;
}
doing this ensures that when an error occurs the script, function, line and error message are reported rather than a IMA crash, the same error checking should also be applied to the callback functions.
I attached my Lua header for reference in case anyone wants it, I gave up on AppGameKit for this project because of the EULA and moved it to raylib but I would have liked to use AGK.
What I like about Lua is being able to mould and shape an API to suit exactly what I want, the way I want it, no compromise, abstract as much or as little as I need on the C++ side and it adds 1000% to the usability factor of just Tier1 BASIC, meta tables, co routines, dynamic tables to name just a few.
I think a full endorsed Lua port of AppGameKit would be good.