1
0
Fork 0

Update for nasal::Context changes

This commit is contained in:
Thomas Geymayer 2018-01-09 20:41:08 +01:00
parent a999b87e06
commit 7c8ab6c52a
9 changed files with 67 additions and 71 deletions

View file

@ -122,9 +122,10 @@ naRef f_createAddonVersion(const nasal::CallContext& ctx)
std::string suffix;
if (ctx.argc == 0 || ctx.argc > 4) {
naRuntimeError(ctx.c,
"AddonVersion.new(versionString) or "
"AddonVersion.new(major[, minor[, patchLevel[, suffix]]])");
ctx.runtimeError(
"AddonVersion.new(versionString) or "
"AddonVersion.new(major[, minor[, patchLevel[, suffix]]])"
);
}
if (ctx.argc == 1) {
@ -137,45 +138,50 @@ naRef f_createAddonVersion(const nasal::CallContext& ctx)
AddonVersionSuffix(suffix))};
return ctx.to_nasal(std::move(ref));
} else {
naRuntimeError(ctx.c,
"AddonVersion.new(versionString) or "
"AddonVersion.new(major[, minor[, patchLevel[, suffix]]])");
ctx.runtimeError(
"AddonVersion.new(versionString) or "
"AddonVersion.new(major[, minor[, patchLevel[, suffix]]])"
);
}
}
assert(ctx.argc > 0);
if (!naIsNum(ctx.args[0])) {
naRuntimeError(
ctx.c, "addons.AddonVersion.new() requires major number as an integer");
if (!ctx.isNumeric(0)) {
ctx.runtimeError(
"addons.AddonVersion.new() requires major number as an integer"
);
}
major = ctx.args[0].num;
major = ctx.requireArg<int>(0);
if (ctx.argc > 1) {
if (!naIsNum(ctx.args[1])) {
naRuntimeError(
ctx.c, "addons.AddonVersion.new() requires minor number as an integer");
if (!ctx.isNumeric(1)) {
ctx.runtimeError(
"addons.AddonVersion.new() requires minor number as an integer"
);
}
minor = ctx.args[1].num;
minor = ctx.requireArg<int>(1);
}
if (ctx.argc > 2) {
if (!naIsNum(ctx.args[2])) {
naRuntimeError(
ctx.c, "addons.AddonVersion.new() requires patch level as an integer");
if (!ctx.isNumeric(2)) {
ctx.runtimeError(
"addons.AddonVersion.new() requires patch level as an integer"
);
}
patchLevel = ctx.args[2].num;
patchLevel = ctx.requireArg<int>(2);
}
if (ctx.argc > 3) {
if (!naIsString(ctx.args[3])) {
naRuntimeError(
ctx.c, "addons.AddonVersion.new() requires suffix as a string");
if (!ctx.isString(3)) {
ctx.runtimeError(
"addons.AddonVersion.new() requires suffix as a string"
);
}
suffix = naStr_data(ctx.args[3]);
suffix = ctx.requireArg<std::string>(3);
}
assert(ctx.argc <= 4);

View file

@ -33,7 +33,7 @@ static naRef f_getHistory(const nasal::CallContext& ctx)
FGFlightHistory* history =
static_cast<FGFlightHistory*>(globals->get_subsystem("history"));
if( !history )
naRuntimeError(ctx.c, "Failed to get 'history' subsystem");
ctx.runtimeError("Failed to get 'history' subsystem");
return ctx.to_nasal(history);
}

View file

@ -99,22 +99,22 @@ SGPropertyNode* from_nasal_helper(naContext c, naRef ref, SGPropertyNode**)
return props;
}
CanvasMgr& requireCanvasMgr(naContext c)
CanvasMgr& requireCanvasMgr(const nasal::ContextWrapper& ctx)
{
CanvasMgr* canvas_mgr =
static_cast<CanvasMgr*>(globals->get_subsystem("Canvas"));
if( !canvas_mgr )
naRuntimeError(c, "Failed to get Canvas subsystem");
ctx.runtimeError("Failed to get Canvas subsystem");
return *canvas_mgr;
}
GUIMgr& requireGUIMgr(naContext c)
GUIMgr& requireGUIMgr(const nasal::ContextWrapper& ctx)
{
GUIMgr* mgr =
static_cast<GUIMgr*>(globals->get_subsystem("CanvasGUI"));
if( !mgr )
naRuntimeError(c, "Failed to get CanvasGUI subsystem");
ctx.runtimeError("Failed to get CanvasGUI subsystem");
return *mgr;
}
@ -124,7 +124,7 @@ GUIMgr& requireGUIMgr(naContext c)
*/
static naRef f_createCanvas(const nasal::CallContext& ctx)
{
return ctx.to_nasal(requireCanvasMgr(ctx.c).createCanvas());
return ctx.to_nasal(requireCanvasMgr(ctx).createCanvas());
}
/**
@ -132,10 +132,9 @@ static naRef f_createCanvas(const nasal::CallContext& ctx)
*/
static naRef f_createWindow(const nasal::CallContext& ctx)
{
return nasal::to_nasal<sc::WindowWeakPtr>
return ctx.to_nasal<sc::WindowWeakPtr>
(
ctx.c,
requireGUIMgr(ctx.c).createWindow( ctx.getArg<std::string>(0) )
requireGUIMgr(ctx).createWindow( ctx.getArg<std::string>(0) )
);
}
@ -145,7 +144,7 @@ static naRef f_createWindow(const nasal::CallContext& ctx)
static naRef f_getCanvas(const nasal::CallContext& ctx)
{
SGPropertyNode& props = *ctx.requireArg<SGPropertyNode*>(0);
CanvasMgr& canvas_mgr = requireCanvasMgr(ctx.c);
CanvasMgr& canvas_mgr = requireCanvasMgr(ctx);
sc::CanvasPtr canvas;
if( canvas_mgr.getPropertyRoot() == props.getParent() )
@ -175,27 +174,27 @@ naRef f_canvasCreateGroup(sc::Canvas& canvas, const nasal::CallContext& ctx)
/**
* Get group containing all gui windows
*/
naRef f_getDesktop(naContext c, naRef me, int argc, naRef* args)
naRef f_getDesktop(const nasal::CallContext& ctx)
{
return nasal::to_nasal(c, requireGUIMgr(c).getDesktop());
return ctx.to_nasal(requireGUIMgr(ctx).getDesktop());
}
naRef f_setInputFocus(const nasal::CallContext& ctx)
{
requireGUIMgr(ctx.c).setInputFocus(ctx.requireArg<sc::WindowPtr>(0));
requireGUIMgr(ctx).setInputFocus(ctx.requireArg<sc::WindowPtr>(0));
return naNil();
}
naRef f_grabPointer(const nasal::CallContext& ctx)
{
return ctx.to_nasal(
requireGUIMgr(ctx.c).grabPointer(ctx.requireArg<sc::WindowPtr>(0))
requireGUIMgr(ctx).grabPointer(ctx.requireArg<sc::WindowPtr>(0))
);
}
naRef f_ungrabPointer(const nasal::CallContext& ctx)
{
requireGUIMgr(ctx.c).ungrabPointer(ctx.requireArg<sc::WindowPtr>(0));
requireGUIMgr(ctx).ungrabPointer(ctx.requireArg<sc::WindowPtr>(0));
return naNil();
}
@ -212,13 +211,13 @@ static sc::ElementPtr f_groupGetChild(sc::Group& group, SGPropertyNode* node)
static void propElementSetData( simgear::PropertyBasedElement& el,
const std::string& name,
naContext c,
const nasal::ContextWrapper& ctx,
naRef ref )
{
if( naIsNil(ref) )
return el.removeDataProp(name);
std::string val = nasal::from_nasal<std::string>(c, ref);
std::string val = ctx.from_nasal<std::string>(ref);
char* end = NULL;
@ -266,7 +265,7 @@ static naRef f_propElementData( simgear::PropertyBasedElement& el,
// Add/delete properties given as hash
nasal::Hash obj = ctx.requireArg<nasal::Hash>(0);
for(nasal::Hash::iterator it = obj.begin(); it != obj.end(); ++it)
propElementSetData(el, it->getKey(), ctx.c, it->getValue<naRef>());
propElementSetData(el, it->getKey(), ctx, it->getValue<naRef>());
return ctx.to_nasal(&el);
}
@ -286,7 +285,7 @@ static naRef f_propElementData( simgear::PropertyBasedElement& el,
else
{
// only name -> get property
propElementSetData(el, name, ctx.c, ctx.requireArg<naRef>(1));
propElementSetData(el, name, ctx, ctx.requireArg<naRef>(1));
return ctx.to_nasal(&el);
}
}

View file

@ -43,12 +43,8 @@ static NasalClipboard::Type parseType(const nasal::CallContext& ctx, size_t i)
return NasalClipboard::PRIMARY;
}
naRuntimeError
(
ctx.c,
"clipboard: invalid arg "
"(expected clipboard.CLIPBOARD or clipboard.SELECTION)"
);
ctx.runtimeError("clipboard: invalid arg "
"(expected clipboard.CLIPBOARD or clipboard.SELECTION)");
}
return NasalClipboard::CLIPBOARD;
@ -58,8 +54,8 @@ static NasalClipboard::Type parseType(const nasal::CallContext& ctx, size_t i)
static naRef f_setClipboardText(const nasal::CallContext& ctx)
{
if( ctx.argc < 1 || ctx.argc > 2 )
naRuntimeError( ctx.c, "clipboard.setText() expects 1 or 2 arguments: "
"text, [, type = clipboard.CLIPBOARD]" );
ctx.runtimeError("clipboard.setText() expects 1 or 2 arguments: "
"text, [, type = clipboard.CLIPBOARD]");
return
naNum
@ -73,8 +69,8 @@ static naRef f_setClipboardText(const nasal::CallContext& ctx)
static naRef f_getClipboardText(const nasal::CallContext& ctx)
{
if( ctx.argc > 1 )
naRuntimeError(ctx.c, "clipboard.getText() accepts max 1 arg: "
"[type = clipboard.CLIPBOARD]");
ctx.runtimeError("clipboard.getText() accepts max 1 arg: "
"[type = clipboard.CLIPBOARD]");
return ctx.to_nasal
(

View file

@ -37,11 +37,11 @@ typedef nasal::Ghost<simgear::HTTP::Request_ptr> NasalRequest;
typedef nasal::Ghost<simgear::HTTP::FileRequestRef> NasalFileRequest;
typedef nasal::Ghost<simgear::HTTP::MemoryRequestRef> NasalMemoryRequest;
FGHTTPClient& requireHTTPClient(naContext c)
FGHTTPClient& requireHTTPClient(const nasal::ContextWrapper& ctx)
{
FGHTTPClient* http = globals->get_subsystem<FGHTTPClient>();
if( !http )
naRuntimeError(c, "Failed to get HTTP subsystem");
ctx.runtimeError("Failed to get HTTP subsystem");
return *http;
}
@ -58,13 +58,11 @@ static naRef f_http_save(const nasal::CallContext& ctx)
const SGPath validated_path = fgValidatePath(filename, true);
if( validated_path.isNull() )
naRuntimeError( ctx.c,
"Access denied: can not write to %s",
filename.c_str() );
ctx.runtimeError("Access denied: can not write to %s", filename.c_str());
return ctx.to_nasal
(
requireHTTPClient(ctx.c).client()->save(url, validated_path.utf8Str())
requireHTTPClient(ctx).client()->save(url, validated_path.utf8Str())
);
}
@ -74,15 +72,16 @@ static naRef f_http_save(const nasal::CallContext& ctx)
static naRef f_http_load(const nasal::CallContext& ctx)
{
const std::string url = ctx.requireArg<std::string>(0);
return ctx.to_nasal( requireHTTPClient(ctx.c).client()->load(url) );
return ctx.to_nasal( requireHTTPClient(ctx).client()->load(url) );
}
static naRef f_request_abort(simgear::HTTP::Request&, const nasal::CallContext& ctx)
static naRef f_request_abort( simgear::HTTP::Request&,
const nasal::CallContext& ctx )
{
// we need a request_ptr for cancel, not a reference. So extract
// the me object from the context directly.
simgear::HTTP::Request_ptr req = ctx.from_nasal<simgear::HTTP::Request_ptr>(ctx.me);
requireHTTPClient(ctx.c).client()->cancelRequest(req);
requireHTTPClient(ctx).client()->cancelRequest(req);
return naNil();
}

View file

@ -58,7 +58,7 @@ static naRef f_node_getPose( const osg::Node& node,
double hdg, pitch, roll;
rotate.getEulerDeg(hdg, pitch, roll);
nasal::Hash pose(ctx.to_nasal(coord), ctx.c);
nasal::Hash pose(ctx.to_nasal(coord), ctx.c_ctx());
pose.set("heading", hdg);
pose.set("pitch", pitch);
pose.set("roll", roll);

View file

@ -300,7 +300,7 @@ static naRef f_airportinfo(nasal::CallContext ctx)
SGGeod pos = getPosition(ctx);
if( ctx.argc > 1 )
naRuntimeError(ctx.c, "airportinfo() with invalid function arguments");
ctx.runtimeError("airportinfo() with invalid function arguments");
// optional type/ident
std::string ident("airport");
@ -367,7 +367,7 @@ static naRef f_navinfo(nasal::CallContext ctx)
if( filter.fromTypeString(id) )
id = ctx.getArg<std::string>(1);
else if( ctx.argc > 1 )
naRuntimeError(ctx.c, "navinfo() already got an ident");
ctx.runtimeError("navinfo() already got an ident");
return ctx.to_nasal( FGNavList::findByIdentAndFreq(pos, id, 0.0, &filter) );
}
@ -412,7 +412,7 @@ static naRef f_courseAndDistance(nasal::CallContext ctx)
SGGeod from = globals->get_aircraft_position(), to, pos;
bool ok = extractGeod(ctx, pos);
if (!ok) {
naRuntimeError(ctx.c, "invalid arguments to courseAndDistance");
ctx.runtimeError("invalid arguments to courseAndDistance");
}
if (extractGeod(ctx, to)) {
@ -424,10 +424,7 @@ static naRef f_courseAndDistance(nasal::CallContext ctx)
double course, course2, d;
SGGeodesy::inverse(from, to, course, course2, d);
naRef result = naNewVector(ctx.c);
naVec_append(result, naNum(course));
naVec_append(result, naNum(d * SG_METER_TO_NM));
return result;
return ctx.newVector(course, d * SG_METER_TO_NM);
}
static naRef f_sortByRange(nasal::CallContext ctx)

View file

@ -102,9 +102,8 @@ static naRef f_standardLocation(const nasal::CallContext& ctx)
else if( type_str == "PICTURES" )
type = SGPath::PICTURES;
else if( type_str != "HOME" )
naRuntimeError
ctx.runtimeError
(
ctx.c,
"os.path.standardLocation: unknown type %s", type_str.c_str()
);

View file

@ -91,7 +91,7 @@ static naRef f_find(const nasal::CallContext& ctx)
size_t pos = ctx.getArg<int>(1, 0);
if( find.size() != 1 )
naRuntimeError(ctx.c, "string::find: single character expected");
ctx.runtimeError("string::find: single character expected");
return pos_to_nasal( str.find(*find.c_str(), pos) );
}