我正在使用谷歌脚本,我想检查一个单元格的类型,如果它的字符串做某事,如果是一个数值.做点别的.
我找不到像isString或isText这样的函数.
这是我的代码,typeof没有检测到单元格包含数字
function Results() {
var activeSheet = SpreadsheetApp.getActiveSpreadsheet();
var pred = activeSheet.getSheetByName("Copy of Predictions");
var real = activeSheet.getSheetByName("16 Results");
var realRes = real.getRange("B7:B61");
var realVal = realRes.getValues();
var cell, cellValue, row, col;
for(col=2;col<16;col++){
var predRes = pred.getRange(7, col, realVal.length);
var predVal = predRes.getValues();
for(row=0;row<predVal.length;row++){
if(predVal[row] == ""){
continue;
}else if(typeof predVal[row] === "number"){
if((predVal[row][0] == realVal[row][0]) && (predVal[row+1][0] == realVal[row+1][0])){
cell = pred.getRange(col, 3);
cellValue = cell.getValue();
cell.setValue(cellValue + 15);
}else{
if(((predVal[row][0] - predVal[row+1][0]) < 0) && ((realVal[row][0] …Run Code Online (Sandbox Code Playgroud) 我有一个调用C函数的Lua脚本.目前这个函数什么也没有返回.我想更改此函数以返回一个字符串,因此在CI中此函数的末尾会将字符串推入Stack.在调用Lua脚本中,我需要取回推送的字符串值.
C初始化和Lua注册
void cliInitLua( void )
{
void* ud = NULL;
Task task;
// Create a new Lua state
L = lua_newstate(&luaAlloc, ud);
/* load various Lua libraries */
luaL_openlibs(L);
/*Register the function to be called from LUA script to execute commands*/
lua_register(L,"CliCmd",cli_handle_lua_commands);
//lua_close(L);
return;
}
Run Code Online (Sandbox Code Playgroud)
这是我的函数返回一个字符串:
static int cli_handle_lua_commands(lua_State *L){
...
...
char* str = ....; /*Char pointer to some string*/
lua_pushstring(L, str);
retun 1;
}
Run Code Online (Sandbox Code Playgroud)
这是我的Lua脚本
cliCmd("Anything here doesn't matter");
# I want to retreive the string str …Run Code Online (Sandbox Code Playgroud)