vscode cocos2d lua 代码片段提示

一直苦于cocos lua没有代码提示,用python脚本输出一份代码提示,api来源cocos引擎下的cocos2d-x/cocos/scripting/lua-bindings/auto/api文件夹

# author toji
#!/usr/bin/python
# -*- coding: UTF-8 -*- 
import json
import os

dir_path = "D:/uzone/luandou_frameworks/cocos2d-x/cocos/scripting/lua-bindings/auto/api"	
file_list = os.listdir(dir_path)
used_key = dict()
# index = 1

def get_format_str(key1):
    s1 =  {
            "prefix": key1,
            "body": [
                key1 + '()'
            ],
        }
    # s1 = json.dumps(s1)
    return s1

for file_name in file_list:
    target_path = dir_path + "/" + file_name
    #test
    # if index == 1:
    print("file_name", file_name)
    in_fo = open(target_path, 'r+', 1, 'utf-8')      #encode = 'utf-8'
    for one_line in in_fo.readlines():
        if one_line.find("-- @function") != -1:
            strings = one_line.split( )
            target_str = strings[3]
            
            if not used_key.get(target_str):
                used_key[target_str] = get_format_str(target_str)
    pass    
    in_fo.close()
    # index = index + 1
pass

out_fo = open(dir_path+"/cocos_lua_api.json", "w+")      
out_fo.write(json.dumps(used_key))
out_fo.close()

 

用户 --> 首选选项 --> 用户代码提示,将得到cocos_lua_api.json文件内容替换vscode创建的提示文件内容即可,

下载链接  https://download.csdn.net/download/twicetwice/12663753

vscode cocos2d lua 代码片段提示_第1张图片

你可能感兴趣的:(cocos2d-x,lua,tool)