예제 #1
0
int main(int argc, const char * argv[])
{
    if (argc < 2)
    {
        printf("no input path\n");
        exit(1);
    }

    const char* apppath = argv[0];
    char* path = strrchr(argv[0], '/');
    char buff[1024] = {0};
    strncat(buff, apppath, path ? (path - apppath + 1) : 0);
    strcat(buff, "converter.lua");
    
    lua_State* L = lua_open();
    luaL_openlibs(L);
    luaopen_cjson(L);
    luaopen_spinebinary(L);
    luaL_dofile(L, buff);
    
    FILE* file = fopen(argv[1], "r");
    
    if (!file)
    {
        printf("can not open file: %s\n", argv[1]);
        exit(1);
    }
    
    fseek(file, 0, SEEK_END);
    size_t len = ftell(file);
    char* data = (char*)malloc(len);
    fseek(file, 0, SEEK_SET);
    fread(data, 1, len, file);
    fclose(file);
    
    lua_pushcfunction(L, _traceback);
    lua_getglobal(L, "convert");
    luaL_checktype(L, -1, LUA_TFUNCTION);
    lua_pushlstring(L, data, len);
    luaL_gsub(L, argv[1], ".json", ".skel");
    lua_pcall(L, 2, 0, -4);
    
    lua_close(L);

    free(data);
    
    return 0;
}
예제 #2
0
파일: app.c 프로젝트: sundoom/nova
VOID app_init(lua_State* ls)
{
	// init the script
	lua_script_init(ls);

	// register app function
	luaL_register(ls, "app", __app_funcs);

	// init all of the modules
	luaopen_lfs(ls);
	lua_time_init(ls);
	lua_timer_init(ls);
	lua_enet_init(ls);
	mongoc_init();
	lua_mongo_init(ls);
	lua_mongotp_init(ls);
	lua_tcp_init(ls);
	luaopen_cjson(ls);
	luaopen_xml(ls);
	CHECK(curl_global_init(CURL_GLOBAL_ALL) == CURLE_OK);
	lua_http_init(ls);
}
예제 #3
0
파일: LuaExport.cpp 프로젝트: txal/XProject
void OpenLuaExport()
{
	LuaWrapper* poWrapper = LuaWrapper::Instance();
	RegLuaDebugger(NULL);

	luaopen_cmsgpack(poWrapper->GetLuaState());
	luaopen_lpeg(poWrapper->GetLuaState());
	luaopen_protobuf_c(poWrapper->GetLuaState());
	luaopen_cjson(poWrapper->GetLuaState());

	RegTimerMgr("GlobalExport");
	RegWordFilter("GlobalExport");
	poWrapper->RegFnList(_global_lua_func, "GlobalExport");

    RegLuaCmd("NetworkExport");
    RegLuaRpc("NetworkExport");
	RegLuaPBPack("NetworkExport");
	RegLuaNetwork("NetworkExport");
	RegLuaSerialize("cseri");

	RegClassSSDBDriver();
	RegClassMysqlDriver();
	RegClassRobot();
}
예제 #4
0
int flexi_init(sqlite3 *db,
               char **pzErrMsg,
               const sqlite3_api_routines *pApi, FlexiliteContext_t **pDBCtx)
{
    int result;

    *pDBCtx = (FlexiliteContext_t *) sqlite3_malloc(sizeof(FlexiliteContext_t));

    FlexiliteContext_t *pCtx = *pDBCtx;

    pCtx->db = db;
    pCtx->L = lua_newstate(lua_alloc_handler, pDBCtx);

    if (pCtx->L == nullptr)
    {
        *pzErrMsg = sqlite3_mprintf("Flexilite: cannot initialize LuaJIT");
        result = SQLITE_ERROR;
        goto ONERROR;
    }

    lua_gc(pCtx->L, LUA_GCSTOP, 0);
    luaL_openlibs(pCtx->L);
    lua_gc(pCtx->L, LUA_GCRESTART, -1);

    /*
     * Open other Lua modules implemented in C
    */
    luaopen_lfs(pCtx->L);
    luaopen_base64(pCtx->L);
    luaopen_lsqlite3(pCtx->L);
    luaopen_cjson(pCtx->L);
    luaopen_cjson_safe(pCtx->L);

    // Create context, by passing SQLite db connection
    if (luaL_dostring(pCtx->L, "return require 'sqlite3'"))
    {
        *pzErrMsg = sqlite3_mprintf("Flexilite require sqlite3: %s\n", lua_tostring(pCtx->L, -1));
        result = SQLITE_ERROR;
        goto ONERROR;
    }

    lua_getfield(pCtx->L, -1, "open_ptr");
    lua_pushlightuserdata(pCtx->L, db);
    if (lua_pcall(pCtx->L, 1, 1, 0))
    {
        *pzErrMsg = sqlite3_mprintf("Flexilite sqlite.open_ptr: %s\n", lua_tostring(pCtx->L, -1));
        result = SQLITE_ERROR;
        goto ONERROR;
    }

    pCtx->SQLiteConn_Index = luaL_ref(pCtx->L, LUA_REGISTRYINDEX);

    // Create context, by passing SQLite db connection
    if (luaL_dostring(pCtx->L,
                      "package.cpath = package.cpath .. ';./libFlexilite.dll'; return require ('DBContext')"))
    {
        *pzErrMsg = sqlite3_mprintf("Flexilite require DBContext: %s\n", lua_tostring(pCtx->L, -1));
        result = SQLITE_ERROR;
        goto ONERROR;
    }

    lua_rawgeti(pCtx->L, LUA_REGISTRYINDEX, pCtx->SQLiteConn_Index);
    if (lua_pcall(pCtx->L, 1, 1, 0))
    {
        *pzErrMsg = sqlite3_mprintf("Flexilite DBContext(db): %s\n", lua_tostring(pCtx->L, -1));
        result = SQLITE_ERROR;
        goto ONERROR;
    }
    pCtx->DBContext_Index = luaL_ref(pCtx->L, LUA_REGISTRYINDEX);

    result = SQLITE_OK;
    goto EXIT;

    ONERROR:
    flexi_free(pCtx);
    *pDBCtx = nullptr;

    EXIT:
    return result;
}