MCPcopy Create free account
hub / github.com/NetHack/NetHack / getPointerValue

Function getPointerValue

sys/libnh/libnhmain.c:818–848  ·  view source on GitHub ↗

convert 'ptr' to the type indicated by 'type'

Source from the content-addressed store, hash-verified

816
817 // convert 'ptr' to the type indicated by 'type'
818 function getPointerValue(name, ptr, type) {
819 // console.log("getPointerValue", name, "0x" + ptr.toString(16), type);
820 switch(type) {
821 case "s": // string
822 // var value = UTF8ToString(getValue(ptr, "*"));
823 return UTF8ToString(ptr);
824 case "p": // pointer
825 if(!ptr) return 0; // null pointer
826 return getValue(ptr, "*");
827 case "c": // char
828 return String.fromCharCode(getValue(ptr, "i8"));
829 case "b":
830 return getValue(ptr, "i8") == 1;
831 case "0": /* 2^0 = 1 byte */
832 return getValue(ptr, "i8");
833 case "1": /* 2^1 = 2 bytes */
834 return getValue(ptr, "i16");
835 case "2": /* 2^2 = 4 bytes */
836 case "i": // integer
837 case "n": // number
838 return getValue(ptr, "i32");
839 case "f": // float
840 return getValue(ptr, "float");
841 case "d": // double
842 return getValue(ptr, "double");
843 case "v": // void
844 return undefined;
845 default:
846 throw new TypeError ("unknown type:" + type);
847 }
848 }
849
850 // sets the return value of the function to the type expected
851 function setPointerValue(name, ptr, type, value = 0) {

Callers 1

getArgFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected