In Lua libraries, I wrote many time the same piece of code.
The purpose of this code is to register each function.
So, I try to write the following PIR macro :
.macro register(tname, fname)
.const .Sub $fname = .fname
$fname.'setfenv'(_lua__GLOBAL)
set $P1, .fname
.tname[$P1] = $fname
.endm
Currently, I obtain the following error :
error:imcc:'$fname' is not a valid register name
in macro '.register' line 30
included from 'src\lib\base64.pir' line 1
make: *** [src\lib\base64.pbc] Error 2
The notation $fname seems limited to local label (.label) and local
variable (.macro_label).
Are there any other notation?
Or is this a new requirement?
The attached patch is a full example for languages/lua/lib/base64.pir
François Perrad.
Index: base64.pir
===================================================================
--- base64.pir (revision 26867)
+++ base64.pir (working copy)
@@ -26,6 +26,13 @@
set_hll_global 'luaopen_base64', entry
.end
+.macro register(tname, fname)
+ .const .Sub $fname = .fname
+ $fname.'setfenv'(_lua__GLOBAL)
+ set $P1, .fname
+ .tname[$P1] = $fname
+.endm
+
.sub 'luaopen_base64'
# print "luaopen_base64\n"
@@ -43,16 +50,9 @@
lua_register($P1, _base64)
- .const .Sub _base64_decode = 'decode'
- _base64_decode.'setfenv'(_lua__GLOBAL)
- set $P1, 'decode'
- _base64[$P1] = _base64_decode
+ .register(_base64, 'decode')
+ .register(_base64, 'encode')
- .const .Sub _base64_encode = 'encode'
- _base64_encode.'setfenv'(_lua__GLOBAL)
- set $P1, 'encode'
- _base64[$P1] = _base64_encode
-
new $P2, 'LuaString'
# set $P2, "Copyright (C) 2008, The Perl Foundation"