当前位置: 首页 > 编程日记 > 正文

Lua bind 和 conf 实现

Lua ,语法简单(极像javascript), 移植性好(纯C实现), 启动速度快,空间占用小, 真不愧是潜入式脚本语言之王。

本人想拿它来做 配置文件(conf),也想加一点IoC, 就是配置脚本可以调用主程序的函数。

实现如下:

repeat_macro.h

#ifndef __REPEAT_MACRO_H__
#define __REPEAT_MACRO_H__

// concatenation
#define CAT(a, b) PRIMITIVE_CAT(a, b)
#define PRIMITIVE_CAT(a, b) a ## b

// binary intermediate split
#define SPLIT(i, im) PRIMITIVE_CAT(SPLIT_, i)(im)
#define SPLIT_0(a, b) a
#define SPLIT_1(a, b) b

// saturating increment and decrement
#define DEC(x) SPLIT(0, PRIMITIVE_CAT(DEC_, x))
#define INC(x) SPLIT(1, PRIMITIVE_CAT(DEC_, x))

#define DEC_0 0, 1
#define DEC_1 0, 2
#define DEC_2 1, 3
#define DEC_3 2, 4
#define DEC_4 3, 5
#define DEC_5 4, 6
#define DEC_6 5, 7
#define DEC_7 6, 8
#define DEC_8 7, 9
#define DEC_9 8, 10
#define DEC_10 9, 11
#define DEC_11 10, 12
#define DEC_12 11, 13
#define DEC_13 12, 14
#define DEC_14 13, 15
#define DEC_15 14, 15

// bit complement
#define COMPL(bit) PRIMITIVE_CAT(COMPL_, bit)
#define COMPL_0 1
#define COMPL_1 0

// nullary parentheses detection
#define IS_NULLARY(x) SPLIT(0, CAT(IS_NULLARY_R_, IS_NULLARY_C x))
#define IS_NULLARY_C() 1
#define IS_NULLARY_R_1 1, ~
#define IS_NULLARY_R_IS_NULLARY_C 0, ~

// boolean conversion
#define BOOL(x) COMPL(IS_NULLARY(PRIMITIVE_CAT(BOOL_, x)))
#define BOOL_0 ()

// recursion backend
#define EXPR(s) PRIMITIVE_CAT(EXPR_, s)
#define EXPR_0(x) x
#define EXPR_1(x) x
#define EXPR_2(x) x
#define EXPR_3(x) x
#define EXPR_4(x) x
#define EXPR_5(x) x
#define EXPR_6(x) x
#define EXPR_7(x) x
#define EXPR_8(x) x
#define EXPR_9(x) x
#define EXPR_10(x) x
#define EXPR_11(x) x
#define EXPR_12(x) x
#define EXPR_13(x) x
#define EXPR_14(x) x
#define EXPR_15(x) x

// bit-oriented if control structure
#define IIF(bit) PRIMITIVE_CAT(IIF_, bit)
#define IIF_0(t, f) f
#define IIF_1(t, f) t

// number-oriented if control structure
#define IF(cond) IIF(BOOL(cond))

// emptiness abstraction
#define EMPTY()

// 1x and 2x deferral macros
#define DEFER(macro) macro EMPTY()
#define OBSTRUCT() DEFER(EMPTY)()

// argument list eater
#define EAT(size) PRIMITIVE_CAT(EAT_, size)
#define EAT_0()
#define EAT_1(a)
#define EAT_2(a, b)
#define EAT_3(a, b, c)
#define EAT_4(a, b, c, d)
#define EAT_5(a, b, c, d, e)
#define EAT_6(a, b, c, d, e, f)
#define EAT_7(a, b, c, d, e, f, g)
#define EAT_8(a, b, c, d, e, f, g, h)
#define EAT_9(a, b, c, d, e, f, g, h, i)
#define EAT_10(a, b, c, d, e, f, g, h, i, j)
#define EAT_11(a, b, c, d, e, f, g, h, i, j, k)

// comma abstractions
#define COMMA() ,
#define COMMA_IF(n) IF(n)(COMMA, EMPTY)()

// repetition construct
#define REPEAT(s, count, macro, data) \
EXPR(s)(REPEAT_I(INC(s), INC(s), count, macro, data)) \
/**/
#define REPEAT_INDIRECT() REPEAT_I
#define REPEAT_I(s, o, count, macro, data) \
IF(count)(REPEAT_II, EAT(6))(OBSTRUCT(), s, o, DEC(count), macro, data) \
/**/
#define REPEAT_II(_, s, o, count, macro, data) \
EXPR(s) _(REPEAT_INDIRECT _()( \
INC(s), o, count, macro, data \
)) \
EXPR OBSTRUCT()(o)(macro OBSTRUCT()(o, count, data)) \
/**/

#endif //__REPEAT_MACRO_H__

lua_bind.h

#ifndef __LUA_BIND_H__
#define __LUA_BIND_H__

extern "C"
{
    #include <lua.h>
}

#include <string>

#ifndef LOG

#define ENABLE_LUA_BIND_H_LOG
#include <stdio.h>
#define LOG(level, format, ...) \
    fprintf(stderr, "[%s][%s][%d]: " format "\n", #level, __FILE__, int(__LINE__), ##__VA_ARGS__)

#endif //LOG

template<typename T>
T lua_get_param(lua_State *state, int index)
{
    LOG(ERROR, "parement type unsupport type");
    return T();
}

template <>
int lua_get_param<int>(lua_State *state, int index)
{
    if (!lua_isnumber(state, index)) {
        LOG(ERROR, "lua argument should be a number\n");
        return 0;
    }

return (int)lua_tonumber(state, index);
}


template <>
bool lua_get_param<bool>(lua_State *state, int index)
{
    if (!lua_isboolean(state, index)){
        LOG(ERROR, "lua argument should be a boolean\n");
        return 0;
    }

return (bool)lua_toboolean(state, index);
}


template <>
double lua_get_param<double>(lua_State *state, int index)
{
    if (!lua_isnumber(state, index)) {
        LOG(ERROR, "lua argument should be a number\n");
        return 0;
    }

return lua_tonumber(state, index);
}


template <>
char const * lua_get_param<char const*>(lua_State *state, int index)
{
    if (!lua_isstring(state, index)){
        LOG(ERROR, "lua argument should be a string\n");
        return "";
    }

return lua_tostring(state, index);
}


template <>
std::string lua_get_param<std::string >(lua_State *state, int index)
{
    if (!lua_isstring(state, index)){
        LOG(ERROR, "lua argument should be a string\n");
        return std::string();
    }

return std::string(lua_tostring(state, index));
}

template<typename T>
int lua_set_result(lua_State *state, T value)
{
    LOG(ERROR, "parement type unsupport type");
    return 0;
}

template <>
int lua_set_result<int>(lua_State *state, int value)
{
    lua_pushnumber(state, double(value));
    return 1;
}

template <>
int lua_set_result<bool>(lua_State *state, bool value)
{
    lua_pushboolean(state, value);
    return 1;
}

template <>
int lua_set_result<double>(lua_State *state, double value)
{
    lua_pushnumber(state, value);
    return 1;
}


template <>
int lua_set_result<char const *>(lua_State *state, char const * value)
{
    if(value) {
        lua_pushstring(state, value);
    } else {
        lua_pushstring(state, "");
    }
    return 1;
}


template <>
int lua_set_result<std::string>(lua_State *state, std::string value)
{
    lua_pushstring(state, value.c_str());
    return 1;
}


#include "repeat_macro.h"

template<typename T>
class function_type_info
{
    public:
        typedef T result_type;
};

#define TEMPLATE_PARAM_TYPE(s, v, arg) COMMA_IF(v) typename CAT(arg, v)
#define TEMPLATE_PARAM_TYPE_LIST(num) EXPR(0)(REPEAT(0, num, TEMPLATE_PARAM_TYPE, arg))

#define DEF_FUN_PARAM_TYPE(s, v, arg) typedef CAT(arg, v) CAT(CAT(arg, v), _type) ;
#define ALL_DEF_FUN_PARAM_TYPE(num) EXPR(0)(REPEAT(0, num, DEF_FUN_PARAM_TYPE, arg))

#define GET_FUN_PARAM_TYPE(s, v, arg) COMMA_IF(v) CAT(arg, INC(v))
#define GET_FUN_PARAM_TYPE_LIST(num) EXPR(0) (REPEAT(0, num, GET_FUN_PARAM_TYPE, arg))

#define DEF_FUNCTION_TYPE_INFO(_, num, arg) \
template< TEMPLATE_PARAM_TYPE_LIST(INC(num)) > \
class function_type_info< arg0 (*)( GET_FUN_PARAM_TYPE_LIST(num) ) > \
{\
    public:\
    ALL_DEF_FUN_PARAM_TYPE(INC(num))\
    typedef arg0 result_type;\
};


DEF_FUNCTION_TYPE_INFO(_, 0, arg)
DEF_FUNCTION_TYPE_INFO(_, 1, arg)
DEF_FUNCTION_TYPE_INFO(_, 2, arg)
DEF_FUNCTION_TYPE_INFO(_, 3, arg)
DEF_FUNCTION_TYPE_INFO(_, 4, arg)
DEF_FUNCTION_TYPE_INFO(_, 5, arg)
DEF_FUNCTION_TYPE_INFO(_, 6, arg)
DEF_FUNCTION_TYPE_INFO(_, 7, arg)
DEF_FUNCTION_TYPE_INFO(_, 8, arg)
DEF_FUNCTION_TYPE_INFO(_, 9, arg)
DEF_FUNCTION_TYPE_INFO(_, 10, arg)
DEF_FUNCTION_TYPE_INFO(_, 11, arg)
DEF_FUNCTION_TYPE_INFO(_, 12, arg)
DEF_FUNCTION_TYPE_INFO(_, 13, arg)
DEF_FUNCTION_TYPE_INFO(_, 14, arg)


#define LUA_PARAM_TYPE(functor,n)  CAT(CAT(functor::arg, n),_type)
#define GET_PARAM_IN(s, v, functor)  LUA_PARAM_TYPE(functor, v) CAT(arg, v) = lua_get_param< LUA_PARAM_TYPE(functor, v) >(state, v);
#define GET_PARAM_FUN(n, functor) EXPR(0)(REPEAT(1, INC(n), GET_PARAM_IN, functor))


#define LUA_CALL_ARG_IN(s, v, arg) COMMA_IF(v) CAT(arg, INC(v))
#define LUA_CALL_FUN_ARG(n, arg) EXPR(0)(REPEAT(0, n, LUA_CALL_ARG_IN, arg))

#define LUA_BIND_NAME(fun, num) CAT(CAT(__lua_bind_, fun), num)
#define DEF_LUA_BIND(fun, num)\
    int LUA_BIND_NAME(fun, num) (lua_State *state){ \
        typedef function_type_info<typeof(&fun)> functor_info_type; \
        GET_PARAM_FUN(num, functor_info_type) \
        typeof(fun(LUA_CALL_FUN_ARG(num, arg))) result = fun(LUA_CALL_FUN_ARG(num, arg));\
        int ret = lua_set_result(state, result); \
        return ret;\
    }


#define DEF_LUA_BIND_VOID(fun, num)\
    int LUA_BIND_NAME(fun, num) (lua_State *state){ \
        typedef function_type_info<typeof(&fun)> functor_info_type; \
        GET_PARAM_FUN(num, functor_info_type) \
        fun(LUA_CALL_FUN_ARG(num, arg));\
        return 0;\
    }


#ifdef ENABLE_LUA_BIND_H_LOG
#undef LOG
#undef ENABLE_LUA_BIND_H_LOG
#endif //ENABLE_LUA_BIND_H_LOG

#endif //__LUA_BIND_H__

lua_conf.hpp

#ifndef __LUA_CONF_H__
#define __LUA_CONF_H__

extern "C"
{
    #include <lua.h>
    #include <lauxlib.h>
    #include <lualib.h>
}

#include "lua_bind.h"

#include <sstream>
#include <string>
#include <assert.h>

#ifndef LOG

#define ENABLE_LUA_CONF_H_LOG
#include <stdio.h>
#define LOG(level, format, ...) \
    fprintf(stderr, "[%s][%s][%d]: " format "\n", #level, __FILE__, int(__LINE__), ##__VA_ARGS__)

#endif //LOG

namespace lua
{

class LuaBase
{
public:
    bool open(char const *filename) {
        if(NULL == filename) return false;
        file_name_ = filename;

state_ = lua_open();
        luaopen_base(state_);
        //luaopen_io(state_);
        //luaopen_string(state_);
        //luaopen_math(state_);
        if (luaL_loadfile(state_, file_name_.c_str())) {
            LOG(ERROR, "cannot load configuration file: %s", file_name_.c_str());
            close();
            return false;
        }
        return true;
    }

typedef int bind_type(lua_State *);

bool registry(char const *name, bind_type fun) {
        if(NULL==name || NULL == state_) return false;
        lua_pushcfunction(state_, fun);
        lua_setglobal(state_,  name);
        return true;
    }

bool load()
    {
      if(NULL == state_) return false;
      if(lua_pcall(state_, 0, 0, 0)){
         LOG(ERROR, "cannot run configuration file: %s", file_name_.c_str());
         close();
         return false;
      }
      return true;
    }


    void close() {
        if(state_) lua_close(state_);
        state_ = NULL;
    }

lua_State *state_;
    std::string file_name_;
};

class LuaConf: public LuaBase
{
public:
    template <typename T>
    T get(char const* name){
        if(NULL==name || NULL == state_) return T();
        lua_getglobal(state_, name);
        if (!lua_isstring(state_, -1)){
            LOG(ERROR, "should be a string\n");
            return T();
        }

std::string value = lua_tostring(state_, -1);
        lua_pop(state_, -1);
        std::istringstream in(value, std::istringstream::in);
        T ret;
        in>>ret;
        return ret;
    }

};

template <>
    int LuaConf::get<int>(char const* name){
        if(NULL==name || NULL == state_) return 0;
        lua_getglobal(state_, name);
        if (!lua_isnumber(state_, -1)) {
            LOG(ERROR, "should be a number\n");
            return 0;
        }

int result = (int)lua_tonumber(state_, -1);
        lua_pop(state_, -1);
        return result;
    }

template <>
    double LuaConf::get<double>(char const* name) {
        if(NULL==name || NULL == state_) return 0;
        lua_getglobal(state_, name);
        if (!lua_isnumber(state_, -1)) {
            LOG(ERROR, "should be a number\n");
            return 0;
        }

double result = lua_tonumber(state_, -1);
        lua_pop(state_, -1);
        return result;
    }

template <>
    std::string LuaConf::get<std::string>(char const* name) {
        if(NULL==name || NULL == state_) return std::string();
        lua_getglobal(state_, name);
        if (!lua_isstring(state_, -1)) {
            LOG(ERROR, "should be a string\n");
            return std::string();
        }

std::string result =  lua_tostring(state_, -1);
        lua_pop(state_, -1);
        return result;
    }

};

#ifdef ENABLE_LUA_CONF_H_LOG
#undef LOG
#undef ENABLE_LUA_CONF_H_LOG
#endif //ENABLE_LUA_CONF_H_LOG

#endif //__LUA_CONF_H__

lua_conf.test.cpp

#include "lua_conf.hpp"
#include <stdio.h>
#include <string>

int say(char const *name) {
    printf("i say %s", name);
    return 1;
}

DEF_LUA_BIND(say, 1)

int main()
{
    lua::LuaConf conf;
    conf.open("1.lua");
    conf.registry("say", LUA_BIND_NAME(say, 1));
    conf.load();
    int a = conf.get<int>("a");
    printf("a=%d\n", a);
    std::string b = conf.get<std::string>("b");
    printf("b=%s\n", b.c_str());
    return 0;
}

makefile

lua_conf.test: lua_conf.test.cpp
    g++ -g -I./ lua_conf.test.cpp -L./ -llua -o lua_conf.test

clean:
    rm lua_conf.test

1.lua

a=4

b=[[good girl]]

say(“hello”)

结果

i say hello

a=4

b=good girl

转载于:https://www.cnblogs.com/napoleon_liu/archive/2010/12/01/1893932.html

相关文章:

通过反射执行get、set方法

Class clazz sourceObj.getClass(); 1、获取所有属性 BeanInfo beanInfo Introspector.getBeanInfo(clazz); PropertyDescriptor[] pds beanInfo.getPropertyDescriptors(); 2、获取指定属性 PropertyDescriptor pd new PropertyDescriptor(fieldName, clazz); Method getM…

h5 移动端 关于监测切换程序到后台或息屏事件和visibilitychange的使用

需求&#xff1a;当我们页面上正在播放视频或者播放背景音乐时&#xff0c;我们屏幕自动息屏或者切换程序去看消息时&#xff0c;我们希望暂停视频或背景音乐&#xff0c;回到程序我们希望继续播放视频或播放背景音乐。小程序上提供了 onUnload返回 onHide退出 onShow重新进入等…

一份整理 | PyTorch是什么,为何选择它

PyTorch是什么 PyTorch的特性 PyTorch是什么 PyTorch是一个基于Python的科学计算包&#xff0c;主要提供以下两种用途&#xff1a; 在GPU算力或其他加速器上作为NumPy的替代一个用于实现神经网络的自动求导库 PyTorch的特性 PyTorch的祖先是Chainer,HIPS autograd,twitter…

jquery实现心算练习

看看大家做完要多长时间&#xff0c;不能上传附近&#xff0c;就只得贴代码。代码如下&#xff1a; 代码 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">2 <htm…

C/C++利用三元组实现稀疏矩阵运算

三元组&#xff08;&#xff08;x&#xff0c;y&#xff09;&#xff0c;z&#xff09;其中&#xff08;x&#xff0c;y&#xff09;表示非零元位置&#xff0c;z表示该坐标的值 由于实际操作时&#xff0c;我们所用的矩阵0非常多&#xff0c;所以一个一个输入值很浪费时间&…

Database项目中关于Procedure sp_refreshsqlmodule_internal的错误

最近项目中发现一怪问题&#xff0c;使用DB项目发布数据库时&#xff0c;总提示 “(110,1): SQL72014: .Net SqlClient Data Provider: Msg 1222, Level 16, State 56, Procedure sp_refreshsqlmodule_internal, Line 67 Lock request time out period exceeded. An error occu…

脱离公式谈谈对反向传播算法的理解

机器学习的训练过程可看作是最优化问题的求解过程。 根据原理 对于函数f(x),如果f(x)在点xt附近是连续可微的&#xff0c;那么f(x)下降最快的方向是f(x)在xt点的梯度的反方向 得到最简单最常用的优化算法&#xff1a;梯度下降法(Gradient Descent Method)。 可以想见&#xf…

如何在Form中使用键弹性域(Key Flexfield)

在应用弹性域之前必须先定义弹性域&#xff0c;定义之前必须先注册表列。如果你的弹性域已经在Oracle Application Object Library中已经定义和注册了&#xff0c;并且弹性域表和列已经在数据库中存在&#xff0c;则忽略1、2、3步骤&#xff0c;适用于关键性也适用于描述性弹性…

什么是SOLID原则(第3部分)

让我们从最后一个 SOLID 原则开始吧&#xff0c;即依赖倒置原则&#xff08;Dependency Inversion Principle&#xff0c;简称 DIP&#xff09;&#xff08;不要和依赖注入Dependency Injection &#xff0c;DI 弄混淆了&#xff09;。这个原则所说的是高级模块不应该依赖具象的…

李彦宏,韩寒等入围本年度《时代百人》候选名单

美国《时代》杂志周六&#xff08;4月3日&#xff09;公布了2010年度 “百位全球最具影响力人物”的200名候选人名单,其中中国最大网络搜索公司“百度”总裁李彦宏也以成功企业家入围候选人,同时入围的还有年仅27岁的80后作家韩寒。 其它“全球最具影响力人物”候选人名单中还包…

win10如何查看NVIDIA驱动的版本

入口 输入&#xff1a;控制面板 选择&#xff1a;硬件和声音 选择NVIDIA控制面板 点击小房子图标 看到版本是391.25

vb中5种打开文件夹浏览框的方法总结(转)

代码 众所周知&#xff0c;在vb中如果是打开某一个文件的话&#xff0c;非常简单&#xff0c;使用CommonDialog组件即可轻松完成&#xff0c;但是他只能选择文件&#xff0c;之后或许选取的文件路径&#xff0c;而如果想要浏览文件夹&#xff0c;就没这么方便了。这里介绍3个办…

R语言文摘:Subsetting Data

原文地址&#xff1a;https://www.statmethods.net/management/subset.html R has powerful indexing features for accessing object elements. These features can be used to select and exclude variables and observations. The following code snippets demonstrate ways…

Ubuntu系统

1. Ubuntu 14.04 LTS安装 直接从官网下载Ubuntu14.04.2LTS http://www.ubuntu.com/download/desktop (你也可以下载最新的14.10---据说改变不大) 个人采用的是U盘安装,用了UltraISO这款软件(百度软件中心中便有---可以不破解试用来完成目的):具体流程: UltraISO上端文件打开,将…

win10下Anaconda如何查看PyTorch版本

以管理员身份打开Anaconda Powershell Prompt 按顺序输入以下三行命令即可

6年iOS开发程序员总结组件化—让你的项目一步到位

纯个人学习笔记分享, 不喜勿喷,自行取关! 技术不缺乏缔造者,网络不缺乏键盘侠,但缺乏分享技术的源动力! 近几年组件化大家吵的沸沸扬扬的&#xff0c;它其实也不是什么黄金圣衣&#xff0c;穿上立马让你的小宇宙提升几个档次&#xff0c;也不是海皇的三叉戟&#xff0c;入手就能…

处理问题的方法--抽象和特例化

事实上我们在软件开发的过程中总是&#xff1a;遇到问题&#xff0c;解决问题&#xff0c;这么一个 简单的过程。处理一般类似问题的时候&#xff0c;我们经过抽象&#xff0c;有的提取算法&#xff0c;有的提取结构&#xff0c;有的提取流程等等&#xff0c;这样的过程可以简单…

121-Best Time to Buy and Sell Stock

题目&#xff1a; Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum p…

控制行输入以下两句命令16倍速播放青年大学习

//得到视频标签 playRate document.getElementsByTagName(video); //改变播放速率 playRate.Bvideo.playbackRate 16;

ios 8+ (xcode 6.0 +)应用程序Ad Hoc 发布前多设备测试流程详解

我们开发的程序在经过simulator以及自己的iOS设备测试后&#xff0c;也基本完成应用程序了&#xff0c;这时候我们就可以把它发布出去了更更多的人去测试&#xff0c;我们可以在iOS平台使用ad hoc实现。 你在苹果购买的开发者会员账号&#xff0c;允许100台设备和你的账号关联。…

SHELL训练营--day5__shell脚本(1)

shell脚本意义 shell是一种脚本语言&#xff0c;具备计算机语言的基本特点&#xff1a;逻辑判断、循环、自定义函数等。shell脚本 主要使用 linux系统的命令&#xff0c;来实现特定目的。可用于自动化运维&#xff0c;提长运维效率。 shell脚本基本结构和运行方法 shell脚本名字…

让程序主窗口不显示在任务栏中

// 这样一句就能搞定了 在Form创建是调用 procedure TfrmWaitWindow.FormCreate(Sender: TObject); begin SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW); end; 相关方法1 Application.Initialize; Application.CreateForm(TForm1, Form1); Application.S…

查缺补漏 | Python控制结构

1. if 表达式的简介写法 x if E else y 意思是如果条件表达式E成立&#xff0c;执行x&#xff0c;否则执行y 等价于 if E&#xff1a;x else:y 2. Python的while循环和其他语言相似(只是少了大括号)&#xff0c;但是for循环区别大很多 for iter_var in iterable_object: sui…

Android学习——R文件丢失异常原因汇总

Console报错&#xff1a;R.java was modified manually! Reverting to generated version! 引言: R文件丢失异常在java开发中是个比较常见的异常&#xff0c;造成这个异常的原因可能非常微小&#xff0c;但是给Android开发者们造成的麻烦可是巨大的&#xff0c;当程序员们费尽千…

举个栗子看如何做MySQL 内核深度优化

2019独角兽企业重金招聘Python工程师标准>>> 本文由云社区发表 作者介绍&#xff1a;简怀兵&#xff0c;腾讯云数据库高级工程师&#xff0c;负责腾讯云CDB内核及基础设施建设&#xff1b;先后供职于Thomson Reuters和YY等公司&#xff0c;PTimeDB作者&#xff0c;曾…

Ubuntu--开启TELNET服务

1 sudo apt-get install xinetd telnetd 安装成功后&#xff0c;系统也会有相应提示&#xff0c; 测试安装完之后就可以Telnet&#xff0c;要是还不行继续 2 sudo vi /etc/inetd.conf 并加入以下一行 telnet stream tcp nowait telnetd /usr/sbin/tcpd /usr/sbin/in.telnetd …

Python的range()函数

如果想产生一个等差数列&#xff0c;用range()函数再合适不过。 range()函数可以有起始值、终值、步长三个参数。 range(start 0,end,step 1) 但是起始值和步长是可以缺省的。起始值的缺省值是0&#xff0c;步长的缺省值是1。 起始值被包含&#xff0c;终值不包含。 为了方…

C++链式继承

继承&#xff0c;对于学习C的每一个人来说&#xff0c;都不会陌生。在Qt的开发中&#xff0c;如果你需要对一个无边框的界面支持move操作&#xff0c;那么你就得通过继承重写虚函数来实现&#xff0c;这并不难&#xff0c;但如果我还需要对一个按钮支持移动&#xff0c;一般情况…

调度框架学习笔记(3)—— 集群调度框架的架构演进过程

本章是 The evolution of cluster scheduler architectures 文章的学习笔记。这篇文章讨论了这些年调度架构是如何发展的以及为什么会这样发展。 首先介绍一下这篇文章的作者&#xff1a;Malte Schwarzkopf&#xff0c;他目前在 MIT 的 PDOS实验室 作博士后&#xff0c;说起作者…

查缺补漏 | Python自定义函数

1 默认参数要放在自定义函数参数列表的最后&#xff0c;也就是说下面的定义是不允许的 2 调用函数时熟悉的是位置参数&#xff0c;但是也可以用关键字参数&#xff0c;也就是调用时把参数名写出来(可以通过它来改变参数的顺序)。不过貌似系统定义的函数不能用关键字参数&#x…