首页 \ 问答 \ 如何使用love2d的外部库(How to use external library with love2d)

如何使用love2d的外部库(How to use external library with love2d)

我正在尝试使用带有love2dluafun库。 lua main.lualua main.lua love . 抱怨缺少fun图书馆。

我用luarocks安装了luarocks


I'm trying to use the luafun library with love2d. Running lua main.lua, however love . complains about the missing fun library.

I have installed luafun with luarocks.


原文:https://stackoverflow.com/questions/42937430
更新时间:2024-03-26 10:03

最满意答案

PHP提供本机执行十进制,八进制,十六进制和二进制数的数学运算。 如果要使用其他类型的数字系统进行计算,则需要将它们转换为上述类型之一。

基本上你使用的是base11号码系统 - 有自定义数字。 PHP提供函数base_convert()来在具有不同基础的系统之间转换数字。 有了这个,你只需要将自定义数字转换为base11,然后将base11转换为十进制,然后计算然后将其转换回来。

Hackish!,但它可以像这样完成。

function add($a, $b) {
    $custom_digits = 'ahkdefgzijm';
    $base11_digits = '0123456789A';

    // translate custom numbers to base11
    $base11_a = strtr($a, $custom_digits, $base11_digits);
    $base11_b = strtr($a, $custom_digits, $base11_digits);

    // translate base11 numbers to decimal
    $decimal_a = base_convert($base11_a, 11, 10);
    $decimal_b = base_convert($base11_b, 11, 10);

    // Do the calculation
    $result = $decimal_a + $decimal_b;

    // Convert result back to base11
    $base11_result = base_convert($result, 10, 11);

    // Translate base11 result into customer digits
    return strtr($base11_result, $base11_digits, $custom_digits);
}

永远不要忘记!:

h + h == k

:)


更灵活的尝试可能是创建两个这样的函数:

function dec_to_custom($n) {
    static $custom_digits = 'ahkdefgzijm';
    static $base11_digits = '0123456789a';
    return strtr(base_convert($n, 10, 11), $base11_digits, $custom_digits);
}

function custom_to_dec($n) {
    static $custom_digits = 'ahkdefgzijm';
    static $base11_digits = '0123456789a';
    $base11 = strtr($n, $custom_digits, $base11_digits);
    return base_convert($base11, 11, 10);
}

并且像你希望的那样使用它们(整数!)数学运算:

echo dec_to_custom(custom_to_dec(1) + custom_to_dec(1));

更新

看起来我的回答太快了。 你已经有了我建议的解决方案,你担心strtr()用法。 我只能说我做了一次类似的任务并进行了大量的分析并最终使用了strtr()因为它表现出最佳性能。


PHP offers to perform math operations for decimal, octal, hexadecimal and binary numbers natively. If you want to do calculations with other kinds of number systems you need to convert them to one of the above kinds.

Basically you are using a base11 number system - having custom digits. PHP offers the function base_convert() to convert numbers between systems with a different base. Having this, you just need to translate your custom digits to base11 then base11 to decimal then calculate and then convert it back.

Hackish!, but it can be done like this.

function add($a, $b) {
    $custom_digits = 'ahkdefgzijm';
    $base11_digits = '0123456789A';

    // translate custom numbers to base11
    $base11_a = strtr($a, $custom_digits, $base11_digits);
    $base11_b = strtr($a, $custom_digits, $base11_digits);

    // translate base11 numbers to decimal
    $decimal_a = base_convert($base11_a, 11, 10);
    $decimal_b = base_convert($base11_b, 11, 10);

    // Do the calculation
    $result = $decimal_a + $decimal_b;

    // Convert result back to base11
    $base11_result = base_convert($result, 10, 11);

    // Translate base11 result into customer digits
    return strtr($base11_result, $base11_digits, $custom_digits);
}

And never forget!:

h + h == k

:)


A more flexible attempt could be to create two functions like this:

function dec_to_custom($n) {
    static $custom_digits = 'ahkdefgzijm';
    static $base11_digits = '0123456789a';
    return strtr(base_convert($n, 10, 11), $base11_digits, $custom_digits);
}

function custom_to_dec($n) {
    static $custom_digits = 'ahkdefgzijm';
    static $base11_digits = '0123456789a';
    $base11 = strtr($n, $custom_digits, $base11_digits);
    return base_convert($base11, 11, 10);
}

And the use them like you wish in (integer!) math operations:

echo dec_to_custom(custom_to_dec(1) + custom_to_dec(1));

Update

Looks like I answered too fast. You had already a solution like I suggested and you are concerned about the strtr() usage. I can only say that I did a similar task once and did a lot of profiling and ended up using strtr() since it showed the best performance.

相关问答

更多
  • 你试过吗? 它应该工作正常。 但是,我建议您不要使用预处理器宏,而应使用实常数。 static const float kGravity = -9.8f; 一般来说,预处理程序指令有点不受欢迎。 以下是关于该主题的更多信息: #define vs Objective-C中的const Did you try it? It should work fine. However, I would encourage you to not use pre-processor macros, but instead ...
  • 我这样做的方法是创建一个模板文件(如果你愿意的话.tpl)并插入将在PHP中用str_replace替换的标记。 代码看起来像这样: 对于template.tpl文件 Something: 对于PHP $template = file_get_contents('template.tpl'); $some_data = 'Some Text'; //could be anything as long as the data ...
  • #ifdef COMPILE_DL_POSIX ZEND_GET_MODULE(first) #endif 这看起来不对。 在config.m4中,您声称首先调用您的扩展名( PHP_NEW_EXTENSION(first, ... )但是您正在检查名为posix的扩展是否已构建为共享。 背景:PHP可以通过两种方式加载扩展(意味着PHP模块不要与Zend Extensions混淆,比如xdebug或opcache - 它们是不同的topi)。 静态编译成PHP或共享。 静态意味着您的扩展是作为PHP的一 ...
  • 您可以使用CSS预处理器(如SASS或LESS)设置变量。 使用SASS它看起来像这样。 $lightGrey :#5e5e5el; a { color: $lightGrey; } 输出: a { color: #5e5e5e; } You can set variables using a CSS PreProcessor such as SASS or LESS. Using SASS it looks like this. $lightGrey :#5e5e5el; a { ...
  • 这里要知道的关键是有一个paginator组件(在控制器中使用)和一个paginator helper(在视图中使用)。 您正在使用的是PaginatorHelper类,它处理与分页相关联的元素的呈现。 不幸的是,没有办法用PaginatorHelper做你想做的事。 如果要执行此操作,最好的方法是扩展PaginatorHelper类并覆盖numbers()方法以返回所需内容。 我已经看过那个特殊的方法,遗憾的是它并不好 - 它超过100行! 但是,我创建了一个继承PaginatorHelper并重写该方法 ...
  • 您可能希望使用base_convert()在实际基数之间进行转换。 然后,从base10(或任何相关的)映射初始基数和新基数之间的值。 也许是这样的 function my_base_convert($input, $fromBase) { $baseMapping = [ '0' => 0, 'a' => 'b', //etc ]; $result = base_convert($input, $fromBase, 10); return ...
  • 不,你不能将字符串解码为数字,因为你不知道函数中$n最后一个值。 例如,最后一个数组索引是0 ( 'a' )和$i=strlen('afu'); 。 0=$n % pow($l, $i) / pow($l, $i - 1) 0=$n % 39304 / 1156 $n=[0,1155]+39304*c; 其中c=0,1,2,3...和$n是循环中$n的最后一个值。 当你找到最后的$n值时,你可以通过在减少周期中对pow($ l,$ i)求和来找到完整的$number 。 这个全额$n位置在pow($l, 1 ...
  • PHP提供本机执行十进制,八进制,十六进制和二进制数的数学运算。 如果要使用其他类型的数字系统进行计算,则需要将它们转换为上述类型之一。 基本上你使用的是base11号码系统 - 有自定义数字。 PHP提供函数base_convert()来在具有不同基础的系统之间转换数字。 有了这个,你只需要将自定义数字转换为base11,然后将base11转换为十进制,然后计算然后将其转换回来。 Hackish!,但它可以像这样完成。 function add($a, $b) { $custom_digits = ...
  • 使用正则表达式从字符串中选择目标数字。 通过php preg_match()运行你的正则表达式。 $str = "ASD - 8.4 - iOS - P-CT"; preg_match("/[\d.]+/", $str, $matches); echo $matches[0]; 在演示中检查代码结果 Use regex to select target digit from string. Run your regex by php preg_match(). $str = "ASD - 8.4 - iO ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)