memory_c API design

Discuss API design here.
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

memory_c API design

Postby Ayuto » Fri Aug 09, 2013 4:01 pm

Hey,

I would like to use this thread to discuss the API design of the memory_c module. We already had a large discussion internally and we are still discussing that, but we would like to know what you are thinking about the current design. Are there any things you would like to add? Or is there something that is too complicated or error-prone? You can also write a general feedback or ask questions about memory hacking. I also created a small library with exported test functions. So you don't need to search a signature for a function. Though, that's also possible if you want. :)

Source code of the test library
The attachment testlib.zip is no longer available


I will add some example very soon. Feel free to post your own examples. I would really appreciate it!! :)


You might want to copy the examples to an editor to get a proper syntax highlighting.

Example #1 - Calling a simple function:

Syntax: Select all

# =============================================================================
# >> IMPORTS
# =============================================================================
# Python
from path import Path

# Source.Python
import memory_c

from memory_c import Convention


# =============================================================================
# >> TEST CODE
# =============================================================================
# Assumed our test library is located at ../addons/source-python/<addon>/
# The second argument is False, because we don't want to add "_srv" to the
# filename.
# This returns a CBinaryFile object for our test library.
testdll = memory_c.find_binary(Path(__file__).parent.joinpath('test'), False)

# Find the symbol "get_int" and create a CPointer instance. You can also use
# testdll.find_symbol('get_int') or testdll['get_int'].
get_int_ptr = testdll.get_int

# Convert the pointer to a CFunction instance using the calling convention
# CDECL. The parameter format characters can be found here:
# http://code.google.com/p/source-python/source/browse/src/thirdparty/dyncall/include/dyncall_signature.h#42
get_int = get_int_ptr.make_function(Convention.CDECL, 'v)i')

# Finally, call it and print the result!
print('Result:', get_int())
Attachments
testlib.zip
(11.36 KiB) Downloaded 363 times
Omega_K2
Senior Member
Posts: 227
Joined: Sat Jul 07, 2012 3:05 am
Location: Europe
Contact:

Postby Omega_K2 » Sat Aug 10, 2013 3:52 pm

So after a brief look at the wrap code (memory_warp_python.cpp) it seems to do what it should, so it should work for now I'd say?


The only thing I see that needs doing is a Python libary with some of the more common things you need. Like hooks for spawning, "ent_fire", UTIL_Remove etc. Satoon pretty much started this though, so I guess it just needs to be updated. But that's a bit OT I guess, since you're talking about c++ side of things :P
Libraries: k2tools
Plugins (any): GSRPG (soon) | Pretty Status List | MySQLAds (soon)
Plugins (game-specific): None atm

If you happen to find a bug or need help, either post in the release threads or contact me in IRC gamesurge.net:6667 / #sourcepython

Return to “API Design”

Who is online

Users browsing this forum: No registered users and 18 guests