---
title: "谷歌拼音输入法支持lua编写api"
author: "lua"
date: "2009-10-29T13:03:55Z"
tags: []
slug: "lua-api"
draft: false
lastmod: "2009-10-29T13:06:10Z"
id: 506365
url: "https://lua.iteye.com/blog/506365"
---

lua利好消息，google拼音加入支持lua。

 

下载最新版本的谷歌拼音，就可以通过lua来扩展它的功能了。

 

api的帮助信息在这里能看到

 

http://www.google.com/ime/pinyin/api.html

 

安装完以后，在 c:\\Documents and Settings\\All Users\\Application Data\\Google\\Google Pinyin 2\\Extensions 可以找到一个base.lua，里面代码写的比较清楚了。

 

比如这个计算模式。

 

function Compute(input)  
  local expr = "return " .. \_AddMathKeyword(input)  
  local func = loadstring(expr)  
  if func == nil then  
    return "-- 未完整表达式 --"  
  end  
  local ret = func()  
  if ret == math.huge then -- div/0  
    return "-- 计算错误 --"  
  end  
  if ret ~= ret then  
    -- We rely on the property that NaN is the only value not equal to itself.  
    return "-- 计算错误 --"  
  end  
  return ret  
end

 

 

ime.register\_command("js", "Compute", "计算模式", "none", "输入表达式，例如3\*log(4+2)")