Example #1
0
int main(int argc, char *argv[]) {
    int i = 0;
    lua_State *L = NULL;
    
    // create lua state and load libraries
    L = luaL_newstate();
    luaL_openlibs(L);
    luaopen_lfs(L);
    
    // create and fill args table
    lua_newtable(L);
    for (i = 0; i < argc; i++) {
        lua_pushnumber(L, i);
        lua_pushstring(L, argv[i]);
        lua_rawset(L, -3);
    }

    // set the global arg table
    lua_setglobal(L, "arg");

    // run the embedded script
    if (luaL_loadbuffer(L, (const char *)script_code, script_code_len, "script_code") ||
        lua_pcall(L, 0, LUA_MULTRET, 0)) {
        fprintf(stderr, "%s\n", lua_tostring(L, -1));
        exit(EXIT_FAILURE);
    }

    // shut down the lua vm
    lua_close(L);

    return EXIT_SUCCESS;
}
Example #2
0
extern "C" __declspec(dllexport) int luaopen_lua_extensions(lua_State *L){
    //luaopen_debug(L);

    open_additional_libs(L);

    luaopen_lfs(L);
    //open_string(L);
    //open_math(L);
    //open_table(L);
    luaopen_marshal(L);
    //open_kb(L);
    //open_log(L); 

    return 0;
}
Example #3
0
int _jason_openlibs(lua_State* L) {
	luaopen_socket_core(L); 	/* Opening the Socket library */
	luaopen_mime_core(L); 		/* Opening the Socket library mime support*/

	luaopen_lfs(L);				/* Opening the Lua Filesystem library */
	luaopen_rings(L);			/* Opening the Rings library */
	luaopen_md5_core(L);		/* Opening the MD5 library */
	luaopen_base64(L);			/* Opening the Base64 library */
	luaopen_des56(L);			/* Opening the DES56 library */
	luaopen_luasystray(L); 		/* Opening the LuaSysTray library */
	luaopen_luamobile(L); 		/* Opening the LuaMobile library */
	/* Opening the LPeg library */
	lua_pushcclosure(L, luaopen_lpeg, 0);
	lua_pushstring(L, "lpeg");
	lua_call(L, 1, 0);
}
Example #4
0
int main(int argc, char **argv) {
	int i;

	if(argc < 2) {
		fprintf(stderr, "needs config file as first argument.\n");
		return -1;
	}

	/* set up Lua state */
	L = lua_open();
	if(L) {
		luaL_openlibs(L);

		luaopen_blitbuffer(L);
		luaopen_drawcontext(L);
		luaopen_einkfb(L);
		luaopen_pdf(L);
		luaopen_djvu(L);
		luaopen_cre(L);
		luaopen_input(L);
		luaopen_util(L);
		luaopen_ft(L);
		luaopen_mupdfimg(L);

		luaopen_lfs(L);

		lua_newtable(L);
		for(i=2; i < argc; i++) {
			lua_pushstring(L, argv[i]);
			lua_rawseti(L, -2, i-1);
		}
		lua_setglobal(L, "ARGV");

		if(luaL_dofile(L, argv[1])) {
			fprintf(stderr, "lua config error: %s\n", lua_tostring(L, -1));
			lua_close(L);
			L=NULL;
			return -1;
		}
	}

	return 0;
}
Example #5
0
LuaInterface::LuaInterface(lua_State* luaVM):lua_state_(0)
{
__ENTER_FUNCTION
    if(luaVM)
    {
        lua_state_ = luaVM;
        lua_settop(lua_state_, 0);
        return;
    }

    lua_state_ = luaL_newstate();
    luaL_openlibs(lua_state_);
    ex_function(lua_state_);
    
    luaopen_lfs(lua_state_);
    luaopen_bson(lua_state_);
    
    lua_settop(lua_state_, 0);
__LEAVE_FUNCTION
}
Example #6
0
File: app.c Project: 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);
}
bool CCLuaStack::init(void)
{
    m_state = lua_open();
    luaL_openlibs(m_state);
    register_all_cocos2dx(m_state);
    register_all_cocos2dx_manual(m_state);
    toluafix_open(m_state);
    luaopen_lfs(m_state);
    luaopen_bit(m_state);

    // Register our version of the global "print" function
    const luaL_reg global_functions [] = {
        {"print", lua_print},
        {NULL, NULL}
    };
    luaL_register(m_state, "_G", global_functions);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
    CCLuaObjcBridge::luaopen_luaoc(m_state);
#endif
    // add cocos2dx loader
    addLuaLoader(cocos2dx_lua_loader);

    return true;
}
Example #8
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;
}
Example #9
0
int main(int argc, char ** argv)
{
  setExecutablePath(argv[0]);

  lua_State *L = lua_open();

  luaL_openlibs(L);

#if USE_IUP
  iuplua_open(L);
  cdlua_open(L);
  cdluaiup_open(L);

  iupkey_open(L);
  iupimlua_open(L);
  IupImageLibOpen ();
  iupcontrolslua_open(L);
  imlua_open(L);
  imlua_open_process(L);
#endif

  luaopen_pack(L);
  luaopen_lfs(L);
  luaopen_marshal(L);
  luaopen_mime_core(L);
  luaopen_socket_core(L);

  pdfdoc_register(L);
  pdfpage_register(L);
  clipboard_register(L);
  luaopen_system(L);
  luaopen_compare(L);

#if _DEBUG 
  lua_pushboolean(L, true);
  lua_setfield(L, LUA_GLOBALSINDEX, "_DEBUG");
#endif
  
  char luaFile[512] = "";
  char playlistFile[512] = "";
  int beginIndex = 1;
  if (argc > 1)
  {
    int strl = strlen(argv[1]);
    bool isLuaFile = strcmp(&argv[1][strl-4], ".lua") == 0;
    if (isLuaFile)
    {
      beginIndex = 2;
      strcpy_s(luaFile, sizeof(luaFile), argv[1]);
    }
    else if (strcmp(&argv[1][strl-5], ".sing") == 0
      || strcmp(&argv[1][strl-4], ".m3u") == 0
      || strcmp(&argv[1][strl-4], ".txt") == 0)
    {
    }
  }
  if (!luaFile[0])
  {
    lua_pushboolean(L, true);
    lua_setfield(L, LUA_GLOBALSINDEX, "APPLOADED");
	const char* execPath = getExecutablePath();
	sprintf_s(luaFile, sizeof(luaFile), "%s\\%s", execPath, "main.lua");
  }
    
  int temp_int = luaL_loadfile(L,luaFile);
  
  int returnval = 0;
  if (temp_int)
  {
    const char *error = lua_tostring(L, -1);
    printf("Error in file: \"%s\"\n", luaFile);
    printf("%s\n", error);
    returnval = 1;
  }
  else
  {
    const char *error;

    for (int i = beginIndex; i < argc; i++)
      lua_pushstring(L, argv[i]);

    if (docall(L,argc-beginIndex,0))
    {
      error = lua_tostring(L, -1);
      if (error)
        std::cout << error;
      returnval = 1;
    }
  }
  close(L);

  return returnval;
}