Lua cleanup: remove OOLua, clean up MyLuaMathTypes (also prod sysgen) #1245

merged 57 commits into from May 6, 2012


None yet
2 participants

johnbartholomew commented May 5, 2012

MyLuaMathTypes has been rewritten into three components: LuaVector, LuaMatrix and LuaFixed.

The galaxy/sysgen code (Galaxy, Sector, StarSystem, CustomSystem, SystemPath) have been moved into src/galaxy/. SBody has been renamed (everywhere) to SystemBody. This doesn't really fit with the "Lua cleanup" theme; I should be able to extract those changes out if someone wants them to go through separate review.

LmrModel has been updated to use LuaVector and LuaMatrix. There have been some minor renames (Matrix -> matrix, math.fixed.deg2rad -> fixed.deg2rad, matrix.orient -> matrix.pose, norm -> unit or unitv, or normalised for the method). I've updated the scripts accordingly, but it's entirely possible that I've broken some models.

ShipType has been updated to use LuaVector. ShipType no longer loads all the Lua standard libraries, it now only loads base, math and debug. That's still more than we want, but is a little better.

CustomSystems has been rewritten using the normal Lua functions, but provides the same structure as before. As with ShipType, it only loads the standard base, math and debug libraries.

pistartup.lua has gone, with most of its content moved into C++ or scrapped. The one bit of it that has been kept in Lua is the string.interp function, which has been moved to data/libs/StringInterp.lua.

OOLua has been completely removed.

johnbartholomew added some commits Apr 5, 2012

return the custom system list directly from GetCustomSystemsForSector
Previous code built a temporary std::list of pointers.
Note that even if a temporary pointer list should be built, a std::list
is horribly inefficient for that use (use a std::vector instead)
use luaL_getmetatable rather than calling lua_getfield directly
This is to mirror the use of luaL_newmetatable.
add LuaConstants::GetConstantFromArg
GetConstantFromArg avoids unnecessarily marshalling a string from the Lua
stack into a const char * and then back to the Lua stack for the table
lookup.  It should more properly be called GetConstantFromStack though,
since the key can be any value on the stack.
add utility function pi_lua_openlib which can be used to open Lua libs
The luaopen_*() functions (which are used to register parts of the Lua
standard library) are designed to be called with lua_call, rather than
being run directly. pi_lua_openlib can be used to make that call.

Example use:

    pi_lua_openlib(l, LUA_DBLIBNAME, &luaopen_base);
    pi_lua_openlib(l, LUA_DBLIBNAME, &luaopen_debug);
    pi_lua_openlib(l, LUA_MATHLIBNAME, &luaopen_math);

to open just the base, debug and math libraries
add a LuaFixed math.deg2rad function which works on numbers of 'fixed's
Accessible through two names: math.rad (which is the standard Lua name)
and math.deg2rad (which is a better, more explicit name and matches Pioneer
remove oolua from CustomSystem.h/cpp and reimplement it with raw Lua API
This also involves some minor structural changes, namely that CustomSystem
and CustomSystemBody objects are now independent heap-allocated objects,
and std::vector<CS/CSB*> is used instead of std::list<CS/CSB>
update custom systems to match changes to custom system/fixed number api
Specifically, math.fixed is now a constructor, so math.fixed.deg2rad can't
be used -- instead, math.deg2rad works on both floating point numbers and
fixed point numbers.
make LuaConsole override the Lua base library print() function
This was previously done in pistartup.lua
add a vector:unit() method which is equivalent to normalised()
Note that vector.unit(x, y, z) and vector.unit(v) are the same function;
if the first argument is a scalar it expects 3 numbers and returns the
normalised vector; otherwise it expects a vector object and returns a
normalised copy of it.

johnbartholomew added some commits May 5, 2012

split LuaVector::PushToLua into PushNewToLua and wrapper PushToLua
PushNewToLua returns a pointer to the Lua-managed vector3d object

@johnbartholomew johnbartholomew referenced this pull request May 6, 2012


Upgrade to Lua 5.2 #1246

@robn robn merged commit e99e894 into pioneerspacesim:master May 6, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment