App-SocialCalc-Multiplayer
view release on metacpan or search on metacpan
socialcalc/formula1.js view on Meta::CPAN
value2 = range.substring(pos1+1, pos2);
pos1 = value1.indexOf("!");
if (pos1 != -1) {
sheet1 = value1.substring(pos1+1);
value1 = value1.substring(0, pos1);
}
else {
sheet1 = "";
}
pos1 = value2.indexOf("!");
if (pos1 != -1) {
value2 = value2.substring(0, pos1);
}
coordsheetdata = sheetdata;
if (sheet1) { // sheet reference
coordsheetdata = scf.FindInSheetCache(sheet1);
if (coordsheetdata == null) { // unavailable
return null;
}
}
rp = scf.OrderRangeParts(value1, value2);
return {sheetdata: coordsheetdata, sheetname: sheet1, col1num: rp.c1, ncols: rp.c2-rp.c1+1, row1num: rp.r1, nrows: rp.r2-rp.r1+1}
}
//*********************
//
// Function Handling
//
//*********************
// List of functions -- Define after functions are defined
//
// SocialCalc.Formula.FunctionList["function_name"] = [function_subroutine, number_of_arguments, arg_def, func_def, func_class]
// function_subroutine takes arguments (fname, operand, foperand, sheet), returns
// errortext or null, pushing result on operand stack.
// number_of_arguments is:
// 0 = no arguments
// >0 = exactly that many arguments
// <0 = that many arguments (abs value) or more
// 100 = don't check
//
// arg_def, if present, is the name of the element in SocialCalc.Formula.FunctionArgDefs.
// func_def, if present, is a string explaining the function. If not, looked up in SocialCalc.Constants.
// func_class, if present, is the comma-separated names of the elements in SocialCalc.Formula.FunctionClasses.
//
// To add a function, just add it to this object.
if (!SocialCalc.Formula.FunctionList) { // make sure it is defined (could have been in another module)
SocialCalc.Formula.FunctionList = {};
}
// FunctionClasses[classname] = {name: full-name-string, items: [sorted list of function names]};
// filled in by SocialCalc.Formula.FillFunctionInfo
SocialCalc.Formula.FunctionClasses = null; // start null to say needs filling in
// FunctionArgDef[argname] = explicit-string-for-arg-list;
// filled in by SocialCalc.Formula.FillFunctionInfo
SocialCalc.Formula.FunctionArgDefs = {};
/*
#
# errortext = SocialCalc.Formula.CalculateFunction(fname, operand, sheet)
#
# Dispatches for function fname.
#
*/
SocialCalc.Formula.CalculateFunction = function(fname, operand, sheet) {
var fobj, foperand, ffunc, argnum, ttext;
var scf = SocialCalc.Formula;
var ok = 1;
var errortext = "";
fobj = scf.FunctionList[fname];
if (fobj) {
foperand = [];
ffunc = fobj[0];
argnum = fobj[1];
scf.CopyFunctionArgs(operand, foperand);
if (argnum != 100) {
if (argnum < 0) {
if (foperand.length < -argnum) {
errortext = scf.FunctionArgsError(fname, operand);
return errortext;
}
}
else {
if (foperand.length != argnum) {
errortext = scf.FunctionArgsError(fname, operand);
return errortext;
}
}
}
errortext = ffunc(fname, operand, foperand, sheet);
}
else {
ttext = fname;
if (operand.length && operand[operand.length-1].type == "start") { // no arguments - name or zero arg function
operand.pop();
scf.PushOperand(operand, "name", ttext);
}
else {
errortext = SocialCalc.Constants.s_sheetfuncunknownfunction+" " + ttext +". ";
}
}
return errortext;
( run in 1.770 second using v1.01-cache-2.11-cpan-b16cb0d3907 )