- Joined
- Nov 7, 2014
- Messages
- 571
StringTable - enables read access to the string table
demo:
JASS:
library StringTable
//! novjass
Information about the type casting used: http://www.hiveworkshop.com/threads/accessing-memory-from-the-script-its-time-of-the-revolution.279262/
Credits: leandrotp, DracoL1ch, Raichu
Information about the string type and the string table: http://www.hiveworkshop.com/threads/documentation-string-type.240473/
Credits: PurgeandFire
Requires:
an update pjass: http://www.hiveworkshop.com/threads/pjass-updates.258738/page-3
Credits: LeP
//! endnovjass
// enable "i2s, s2i" type casting that was possible in v1.23- via the "return bug"
//
globals
integer StringTable_integer // not used, needed to fool jasshelper
integer l__StringTable_integer
string StringTable_string // not used, needed to fool jasshelper
string l__StringTable_string
endglobals
private function set_integer takes integer i returns nothing
set l__StringTable_integer = i
return // prevent jasshelper from inlining this function
endfunction
private function set_string takes string s returns nothing
set l__StringTable_string = s
return // prevent jasshelper from inlining this function
endfunction
// leandrotp:
// This is because of a bug that occurs during the parsing of the script:
// if you declare a local variable with the same name as a global, it will
// cause the type of the global variable to be transformed, and become
// the type of the local!
//
// \@Hack =)
function Enable_String_Table_Read_Access takes nothing returns nothing
// vJass feature: local variable shadowing
// http://www.wc3c.net/vexorian/jasshelpermanual.html#shadowing
//
local string StringTable_integer // jasshelper will implicitly rename this to l__StringTable_integer
local integer StringTable_string // jasshelper will implicitly rename this to l__StringTable_string
endfunction
// //# +nosemanticerror
// function I2SH takes integer i returns string
// call set_integer(i)
// return l__StringTable_integer
// endfunction
//# +nosemanticerror
// function SH2I takes string s returns integer
// call set_string(s)
// return l__StringTable_string
// endfunction
struct StringTable extends array
//# +nosemanticerror
static method operator[] takes integer i returns string
call set_integer(i)
return l__StringTable_integer
endmethod
//# +nosemanticerror
// static method get_string_id takes string s returns integer
// call set_string(s)
// return l__StringTable_string
// endmethod
endstruct
//# +nosemanticerror
function GetStringId takes string s returns integer
call set_string(s)
return l__StringTable_string
endfunction
endlibrary
demo:
JASS:
library GetMapName initializer init requires StringTable
globals
private string MAP_NAME = ""
endglobals
private function init takes nothing returns nothing
// when the function "config" is called this is it's first line
//
// call SetMapName("Just another Warcraft III map")
// or
// call SetMapName("TRIGSTR_003")
//
set MAP_NAME = StringTable[2]
if SubString(MAP_NAME, 0, 8) == "TRIGSTR_" then
set MAP_NAME = GetLocalizedString(MAP_NAME)
endif
endfunction
function GetMapName takes nothing returns string
return MAP_NAME
endfunction
endlibrary
library demo initializer init requires GetMapName
function init takes nothing returns nothing
call BJDebugMsg("map name: " + GetMapName())
endfunction
endlibrary