如何使用love2d的外部库(How to use external library with love2d)
我正在尝试使用带有
love2d
的luafun
库。lua main.lua
,lua main.lua
love .
抱怨缺少fun
图书馆。我用
luarocks
安装了luarocks
。I'm trying to use the
luafun
library withlove2d
. Runninglua main.lua
, howeverlove .
complains about the missingfun
library.I have installed
luafun
withluarocks
.
原文:https://stackoverflow.com/questions/42937430
最满意答案
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 usingstrtr()
since it showed the best performance.
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
#define负数?(#define negative numbers?)[2023-11-18]
你试过吗? 它应该工作正常。 但是,我建议您不要使用预处理器宏,而应使用实常数。 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 ...
-
自定义PHP扩展(custom PHP extension)[2023-04-30]
#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的一 ... -
定义自定义颜色(Define custom color)[2021-12-19]
您可以使用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 { ... -
蛋糕PHP中的自定义分页(Custom Pagination in Cake PHP)[2019-12-28]
这里要知道的关键是有一个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 ...
-
用PHP反转自定义基本编码(Reverse custom base encode in PHP)[2023-11-12]
不,你不能将字符串解码为数字,因为你不知道函数中$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 ...